QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746338#9352. Highway Busesviq2347WA 8ms85932kbC++142.4kb2024-11-14 14:18:232024-11-14 14:18:24

Judging History

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

  • [2024-12-10 15:19:00]
  • hack成功,自动添加数据
  • (/hack/1277)
  • [2024-11-14 14:18:24]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:85932kb
  • [2024-11-14 14:18:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
enum{_n=200007,_m=55};
using ll=int64_t;
u32string G[_n],EX,E[_n];
int ex,siz[_n],R,up[_n],dth;
bitset<_n> B;
void dfs(int u,int p){
	for(siz[u]=1;int v:G[u]) if(v!=p)
		dfs(v,u),siz[u]+=siz[v];
}

u32string I[_n],D[_n],S[_n],P[_n];
vector<u32string> H[_n];
bool dfs1(int u,int p,int t,int d){
	int A=t-siz[u],k=0,l=0;
	dth=max(dth,d),I[d]+=u,D[u]+=d;
	for(int v:G[u]) if(v!=p&&~B[v]){
		A=max(A,k=siz[v]);
		if(dfs1(v,u,t,d+1))
			siz[u]=t-k,l=1;
	}
	if(!R&&2*A<=t) R=u,l=1;
	return l;
}
void dfs2(int u){
	I[0]+=u,dth=0;
	for(B[u]=1;int v:G[u]) if(~B[v])
		dfs1(v,R=0,siz[v],1),up[R]=u,S[u]+=R;
	H[u].insert(H[u].end(),make_move_iterator(I),make_move_iterator(I+dth+1));
	for(int v:S[u]) dfs2(v);
}

struct NOD{ll x;mutable int i;bool operator<(NOD $)const{return x>$.x;}};
priority_queue<NOD>Q;
ll c1[_n],c2[_n],ret[_n],ans[_n];
int n,f[_n];
int d[_m][_n],cur1[_n],cur2[_n],cur0[_m];

void work(ll*c){
for(ret[1]=0,Q.push({c[1],1});
	!Q.empty();){
	auto[x,u]=Q.top(); Q.pop();
	for(int i=0;i<ex;++i)
		for(;cur0[i]<n;++cur0[i]){
			int v=P[i][cur0[i]];
			if(d[i][v]+d[i][u]>f[u]) break;
			if(!~ret[v])
				ret[v]=x,Q.push({ret[v]+c[v],v});
		}
	for(int i=u,j=D[u].size();--j,i;i=up[i])
		while(cur1[i]<H[i].size()){
			int v=H[i][cur1[i]][cur2[i]];
			if(cur1[i]+D[u][j]>f[u]) break;
			if(!~ret[v])
				ret[v]=x,Q.push({ret[v]+c[v],v});
			if(++cur2[i]==H[i][cur1[i]].size())
				++cur1[i],cur2[i]=0;
		}
}
for(int i=1;i<=n;++i)
	ans[i]=min(ans[i],ret[i]);
}

int g[_n]; int get(int x){return g[x]?g[x]=get(g[x]):x;}
int q[_n],l,r,m,T;
int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>m>>T;
	for(int i=1,w;i<=n;++i)
		cin>>f[i]>>c1[i]>>w,c2[i]=c1[i]+w*ll(T-1);
	for(int i=0,u,v;i<m;++i){
		cin>>u>>v;
		if(get(u)==get(v)) EX+=u;
		else G[u]+=v,G[v]+=u,g[get(u)]=get(v);
		E[u]+=v,E[v]+=u;
	}
	sort(&EX[0],&EX[EX.size()]);
	EX.resize(ex=unique(&EX[0],&EX[EX.size()])-&EX[0]);
	for(int i=0;i<ex;++i){
		memset(d[i]+1,-1,4*n);
		d[i][EX[i]]=0;
		for(q[r=1,l=0]=EX[i];l!=r;++l){
			int u=q[l]; P[i]+=u;
			for(int v:E[u]) ~d[i][v]?:(
				d[i][v]=d[i][u]+1,
				q[r++]=v); }
	}
	dfs(1,0), dfs2(1);
	memset(ans+1,9,8*n);
	memset(ret+1,-1,8*n),work(c1);
	bzero(cur0,4*ex),bzero(cur1+1,4*n),bzero(cur2+1,4*n);
	memset(ret+1,-1,8*n),work(c2);
	for(int i=1;i<=n;++i) cout<<ans[i]<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 58272kb

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: 8ms
memory: 85932kb

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
1158491264
1166370876
1230036125
1166370876
1196112200
1192655096
1158491264
1208125266
1158491264
1158491264
1196497260
1246120727
1158491264
1158491264
1192655096
1196497260
1192655096
1154051011
1208125266
1165553259
1158491264
1196112200
1209885938
1158491264
1680607611
1158491264
1154051011
1...

result:

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