QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808837#9352. Highway Busesfree_windyWA 7ms26724kbC++203.7kb2024-12-11 07:40:052024-12-11 07:40:13

Judging History

你现在查看的是最新测评结果

  • [2024-12-11 07:40:13]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:26724kb
  • [2024-12-11 07:40:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int s=0,z=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')z=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){	
		s=(s<<3)+(s<<1)+(c^48);
		c=getchar();
	}
	return s*z;
}
const int N = 4e5+55;
int fr[N],to[N*2],nt[N*2],cnt;
void ct(int x,int y){
	nt[++cnt]=fr[x];
	fr[x]=cnt;
	to[cnt]=y;
	return;
}
#define mkp make_pair
int n,m;
int T;
int f[N],w[N],c[N];
int ans[N],sz[N],ms[N];
int root;
bool vis[N],vis2[N],vis3[N];
int deep[N];
vector<int>ln[N];
vector<int>s[N];
vector<int>lk[N],up[N];
int p[N];
int jl[N];
int mn[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
void find_root(int x,int fa,int w){
	sz[x]=1;
	ms[x]=0;
	for(int i=fr[x];i;i=nt[i]){
		if(to[i]==fa||vis2[to[i]]) continue;
		if(vis[i]) continue;
		find_root(to[i],x,w);
		sz[x]+=sz[to[i]];
		ms[x]=max(ms[x],sz[to[i]]);
	}
	ms[x]=max(ms[x],w-sz[x]);
	if(!root||ms[root]>ms[x]) root=x;
}
void dfs2(int x,int fa){
	ln[root].push_back(x);
	lk[x].push_back(root);
	up[x].push_back(deep[x]);
	for(int i=fr[x];i;i=nt[i]){
		if(to[i]==fa) continue;
		if(vis[i])continue;
		if(vis2[to[i]]){
			continue;
		}
		deep[to[i]]=deep[x]+1;
		dfs2(to[i],x);	
	}
	return ;
}
bool px(int x,int y){
	return deep[x]<deep[y];
}
void cl(){
	int x=root;
	deep[root]=0;
	dfs2(root,0);
	sort(ln[x].begin(),ln[x].end(),px);
	for(int i:ln[x]) s[x].push_back(deep[i]);
}
void dfz(int x){
	cl();
	vis2[x]=1;
	for(int i=fr[x];i;i=nt[i]){
		if(vis[i]) continue;
		if(vis2[to[i]]) continue;
		root=0;
		find_root(to[i],x,sz[to[i]]);
		dfz(root);
	} 
}
void dfs1(int x,int fa){
	deep[x]=deep[fa]+1;
	for(int i=fr[x];i;i=nt[i]){
		if(to[i]==fa) continue;
		if(vis[i]) continue;
		if(deep[to[i]]){
			vis[i^1]=1;
			vis[i]=1;
			vis3[x]=1;
			vis3[to[i]]=1;
			continue;
		}
		dfs1(to[i],x);
	}
	return ;
}
queue<int>q2;
void solve(){
	dfs1(1,0);
	root=0;
	find_root(1,0,n);
	dfz(root);
}
void dj(){
	memset(jl,0x3f,sizeof jl);
	q.push(mkp(c[1],1));
	for(int i=1;i<=n;i++) p[i]=0;
	jl[1]=0;
	while(!q.empty()){
		int x=q.top().second,ws=q.top().first;
		q.pop();
		if(ws>jl[x]+c[x]) continue;
		if(vis3[x]){
			for(int i=1;i<=n;i++) deep[i]=0;
			for(int i=0;i<=n;i++) mn[i]=1e16;
			deep[x]=1;
			q2.push(x);
			mn[f[x]]=jl[x]+c[x];
			while(!q2.empty()){
				int x1=q2.front();
				if(f[x1]>deep[x1]+1){
					mn[f[x1]-deep[x1]+1]=min(mn[f[x1]-deep[x1]+1],jl[x1]+c[x1]);
				}
				q2.pop();
				for(int i=fr[x1];i;i=nt[i]){
					if(deep[to[i]])continue;
					deep[to[i]]=deep[x1]+1;
					q2.push(to[i]);
				}
			}
			for(int i=n-1;i>=0;i--){
				mn[i]=min(mn[i],mn[i+1]);
			}
			for(int i=1;i<=n;i++){
				if(jl[i]>mn[deep[i]-1]){
					jl[i]=mn[deep[i]-1];
					q.push(mkp(mn[deep[i]-1],i));
				}
			}
		}
		else{
			for(int i=0;i<lk[x].size();i++){
				int t=lk[x][i],cx=f[x]-up[x][i];
				if(cx<0) continue;
				for(;p[t]<ln[t].size();p[t]++){
					if(s[t][p[t]]>cx) break;
					if(jl[ln[t][p[t]]]<ws) continue;
					jl[ln[t][p[t]]]=ws;
					q.push(mkp(ws+c[ln[t][p[t]]],ln[t][p[t]]));
					if(vis3[ln[t][p[t]]]) q.push(mkp(ws,ln[t][p[t]]));
				}
			}
			
		}
	}
}
signed main(){
//	freopen("1.in","r",stdin);
//	freopen("my.out","w",stdout);
	cnt=1;
	n=read(),m=read(),T=read();
	for(int i=1;i<=n;i++){
		f[i]=read(),c[i]=read(),w[i]=read();
	}
	for(int x,y,i=1;i<=m;i++){
		x=read(),y=read();
		ct(x,y);
		ct(y,x); 
	}
	solve();
	dj();
	for(int i=1;i<=n;i++) ans[i]=jl[i];
	T--;
	for(int i=1;i<=n;i++) c[i]=c[i]+w[i]*T;
	dj();
	for(int i=1;i<=n;i++){
		if(ans[i]<jl[i]){
			cout<<ans[i]<<"\n";
		}
		else{
			cout<<jl[i]<<"\n";
		}
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 26420kb

input:

6 6 2
1 50 -40
1 2 100
2 1 100
2 4 100
3 1 100
1 1 100
1 2
2 3
3 4
4 2
2 5
6 1

output:

0
10
52
52
52
10

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 26724kb

input:

500 540 1000000
1 831790353 70
3 624594642 -127
2 189318946 -92
1 858646508 320
4 76999645 671
4 780012318 880
2 51254764 -12
2 420182468 -333
3 314764053 -36
1 560114854 -419
2 484412868 -31
3 466851594 6
4 535326027 732
4 430602789 578
1 605236859 43
4 633715178 896
3 110060408 -9
4 878946915 -654...

output:

0
1176413615
1184293227
1205507860
1176413615
1175315379
1186581094
1176413615
1175315379
1176413615
1154051011
1175315379
1184293227
1154051011
1154051011
1175315379
1175315379
1175315379
1188704057
1175315379
1175315379
1176413615
1175315379
1188704057
1176413615
1214335628
1175315379
1188704057
1...

result:

wrong answer 2nd lines differ - expected: '1277292628', found: '1176413615'