QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759912#9352. Highway Buses275307894a#TL 2371ms256648kbC++143.4kb2024-11-18 13:17:312024-11-18 13:17:32

Judging History

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

  • [2024-12-10 15:19:00]
  • hack成功,自动添加数据
  • (/hack/1277)
  • [2024-11-18 13:17:32]
  • 评测
  • 测评结果:TL
  • 用时:2371ms
  • 内存:256648kb
  • [2024-11-18 13:17:31]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*4+5,K=1000+5,mod=1e8+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,m,T,A[N],B[N],C[N];
int fa[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
vector<int> S[N],G[N];
int ns[N],nh,id[N];
int d[105][N],pt[105][N];
int dis[20][N],jp[20][N],st[N],sh;
vector<int> e[N];int ed[N];
int siz[N],dp[N],vis[N],cnt,rt;
void getsiz(int x,int La){
	siz[x]=1;
	for(int i:S[x]) if(i^La&&!vis[i]) getsiz(i,x),siz[x]+=siz[i];
}
void DP(int x,int La){
	dp[x]=cnt-siz[x];
	for(int i:S[x]) if(i^La&&!vis[i]) DP(i,x),dp[x]=max(dp[x],siz[i]);
	if(dp[x]<dp[rt]) rt=x;
}
void build(int x,int deep){
	getsiz(x,0);cnt=siz[x];dp[rt=0]=INF;DP(x,0);vis[x=rt]=1;
	queue<int> q;q.push(x);dis[deep][x]=0;
	while(!q.empty()){
		int y=q.front();q.pop();
		e[x].push_back(y);jp[deep][y]=x;
		for(int i:S[y]) if(!vis[i]&&dis[deep][i]>dis[deep][y]+1) dis[deep][i]=dis[deep][y]+1,q.push(i);
	}
	reverse(all(e[x]));
	for(int i:S[x]) if(!vis[i]) build(i,deep+1);
}
priority_queue<pair<ll,int> > Q;
ll ans[N],f[N];
void add(int x,int z,ll w){
	// gdb(x,z,w);
	for(int i=18;~i;i--) if(jp[i][x]){
		int v=jp[i][x];
		while(ed[v]>=0&&dis[i][e[v][ed[v]]]+dis[i][x]<=z){
			if(f[e[v][ed[v]]]>w){
				f[e[v][ed[v]]]=w;
				Q.emplace(-(w+B[e[v][ed[v]]]),e[v][ed[v]]);
				// gdb(x,z,i,v,dis[i][e[v][ed[v]]],dis[i][x],e[v][ed[v]]);
			}
			ed[v]--;
		}
	}
}
void work(){
	Me(f,0x3f);
	for(int i=1;i<=n;i++) ed[i]=e[i].size()-1;
	f[1]=0;Q.emplace(-B[1],1);
	while(!Q.empty()){
		auto [w,x]=Q.top();Q.pop();w*=-1;
		add(x,A[x],w);
		for(int i=1;i<=nh;i++) if(d[i][x]<=A[x]) add(ns[i],A[x]-d[i][x],w);
	}
	for(int i=1;i<=n;i++) ans[i]=min(ans[i],f[i]);
}
void Solve(){
	scanf("%d%d%d",&n,&m,&T);
	for(int i=1;i<=n;i++) scanf("%d%d%d",&A[i],&B[i],&C[i]);
	iota(fa+1,fa+n+1,1);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		G[x].push_back(y);G[y].push_back(x);
		if(GF(x)^GF(y)) fa[GF(x)]=GF(y),S[x].push_back(y),S[y].push_back(x),gdb(x,y);
		else ns[++nh]=x,ns[++nh]=y;
	}
	sort(ns+1,ns+nh+1);nh=unique(ns+1,ns+nh+1)-ns-1;
	Me(d,0x3f);
	for(int i=1;i<=nh;i++){
		id[ns[i]]=i;
		d[i][ns[i]]=0;queue<int> q;
		q.push(ns[i]);
		for(int j=1;j<=n;j++){
			int x=q.front();q.pop();pt[i][j]=x;
			for(int j:G[x]) if(d[i][j]>d[i][x]+1) d[i][j]=d[i][x]+1,q.push(j);
		}
	}
	Me(dis,0x3f);
	build(1,0);
	Me(ans,0x3f);
	work();
	for(int i=1;i<=n;i++) B[i]+=(T-1)*C[i];
	work();
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 8ms
memory: 126524kb

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
1277292628
1239671692
1255261807
1284074004
1270230633
1239671692
1284074004
1271369537
1277292628
1205507860
1270615693
1300179417
1205507860
1205507860
1239671692
1251564675
1239671692
1284004371
1239671692
1239671692
1277292628
1270230633
1284004371
1277292628
1255261807
1276194392
1247939403
1...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 8ms
memory: 128564kb

input:

500 540 1000000
1 613142394 -268
5 920609625 740
2 755612530 -255
2 23678897 -4
5 325892468 291
5 707223319 -140
1 679600699 -138
5 625157055 690
2 141819870 995
1 250348582 -219
2 581461324 -580
4 339782234 -82
5 810851082 230
3 378119535 158
4 295102386 677
5 854435300 21
3 565535907 -465
2 820995...

output:

0
2421015760
2617367920
2694215005
2812156460
2412108889
2370843291
2786283443
2412108889
2197157944
2412108889
2633707306
2370843291
2478757415
2672183755
2478757415
2633707306
2812156460
1984181483
2464420418
2548091380
2421015760
2421015760
2412108889
2421015760
2421015760
2412108889
2412108889
2...

result:

ok 500 lines

Test #4:

score: 0
Accepted
time: 7ms
memory: 124888kb

input:

500 544 1000000
2 587500219 -573
3 800375803 -606
2 332196789 -11
2 782258272 270
2 690828422 -145
2 642751384 -107
4 78645508 -68
3 692764955 364
5 739361677 -104
4 139030619 -125
5 698401632 -121
3 654935300 401
4 70734757 -57
2 763502749 911
1 71485824 836
1 292976518 -290
1 743618801 659
2 64895...

output:

0
425794735
442014967
675968705
311908134
675968705
336563578
425794735
523701048
479984544
425794735
425794735
425794735
708001283
311908134
1653971237
425794735
580659172
425794735
487630114
311908134
450399440
1653971237
425957613
425794735
425957613
336604992
336604992
425794735
436034689
425794...

result:

ok 500 lines

Test #5:

score: 0
Accepted
time: 12ms
memory: 129048kb

input:

500 543 1000000
4 753661240 -312
2 281450837 -151
9 28464686 987
7 685967710 490
8 592650944 542
10 141100249 83
10 646501804 -94
3 337312645 294
2 904175548 -870
8 281667853 -136
3 36477141 -26
5 476645115 -195
1 21897824 -7
10 517151723 150
1 291410319 941
7 993616997 143
10 628559241 -428
8 10757...

output:

0
445387723
445387723
450719457
455897864
445387723
449974501
449974501
449974501
444157947
449974501
449974501
449974501
449974501
449974501
445387723
441661552
449974501
449974501
449974501
444157947
444157947
444157947
449974501
444157947
444157947
449974501
445387723
441661552
449974501
45156161...

result:

ok 500 lines

Test #6:

score: 0
Accepted
time: 4ms
memory: 131396kb

input:

500 547 1000000
7 579418 0
1 769742 0
1 133755 0
2 996071 0
2 96075 893
7 484503 0
7 645976 141
6 80570 0
2 33751 124
4 218617 701
5 686104 0
1 675119 586
3 294461 0
5 319865 0
9 178301 179
1 547068 0
1 96921 802
3 725739 58
8 646648 0
4 667865 0
6 816462 0
4 901406 37
4 834211 0
1 364051 263
2 1014...

output:

0
653962
626600
579418
626600
603269
603269
626600
626600
634782
626600
672297
579418
626600
626600
579418
626600
579418
626600
672297
626600
661975
672297
746441
626600
661975
626600
626600
626600
626600
579418
626600
653962
661975
626600
626600
579418
579418
626600
579418
579418
626600
634782
6266...

result:

ok 500 lines

Test #7:

score: 0
Accepted
time: 8ms
memory: 130540kb

input:

500 549 1000000
8 275979 799
2 323404 0
8 286448 610
2 877230 292
5 111405 972
2 686865 757
6 542128 0
9 823472 705
8 551203 0
9 900802 0
8 497319 554
2 60284 473
1 128784 147
1 390099 282
1 376548 407
7 444338 502
10 496911 293
7 133528 0
1 949531 669
8 569605 459
1 310534 504
2 705803 0
5 954861 0...

output:

0
308634
296602
275979
275979
275979
308634
296754
296602
275979
296602
308634
275979
275979
275979
296602
275979
296602
275979
296602
308634
296602
275979
300889
275979
275979
275979
275979
296754
296602
324141
275979
296754
296754
308634
296602
308634
308634
275979
296754
275979
275979
324141
2759...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 115ms
memory: 158988kb

input:

30000 30047 786577
2 418118 886
1 923620 -1
1 396304 59
1 357673 0
1 12272 51
2 797480 0
2 41479 797
1 970539 -1
1 608143 0
2 415150 0
1 459616 0
1 739232 742
1 917012 -1
1 165211 0
1 637917 550
1 238131 0
2 232835 258
2 610877 0
1 17235 0
2 112947 446
2 828314 0
2 179873 782
2 333590 0
1 961918 194...

output:

0
80494179
83741087
62038907
76473105
104910654
116145079
108446496
88716481
94285072
115284209
99860695
77584533
119165550
81758989
77570762
142596283
79902868
77267149
95599129
114945135
73806480
108069554
77051483
76742645
57016312
152581721
89223155
76282889
122548472
23429774
107080496
76205230...

result:

ok 30000 lines

Test #9:

score: 0
Accepted
time: 155ms
memory: 159340kb

input:

30000 30050 605850
9 564340 974
2 843284 -1
1 398311 922
9 478997 556
7 671058 -1
3 671222 872
2 943222 -1
3 357119 393
8 108556 258
2 579805 0
5 452884 0
7 578644 871
4 863186 157
8 47757 0
10 635134 678
4 73374 1000
4 614076 0
3 549192 0
8 945587 0
5 67239 48
5 943401 992
9 345170 459
6 164234 0
5...

output:

0
9452611
15305660
6254895
8166386
10065348
6017741
6884440
17917177
6017741
7241812
5274395
6017741
6017741
10160098
6017741
8872246
7061933
10080339
8597089
5885039
6017741
6017741
12747501
7589567
13233135
6017741
12499965
6017741
8353713
11425708
6017741
6017741
6017741
7468089
8335888
9588729
6...

result:

ok 30000 lines

Test #10:

score: 0
Accepted
time: 1123ms
memory: 251480kb

input:

200000 200047 812175
1 850300 0
1 913813 609
1 148997 755
1 5275 0
1 989899 -1
1 843074 -1
1 131757 0
1 713341 0
1 530046 919
1 243794 0
1 127575 558
1 385431 694
1 94653 0
1 556880 189
1 718137 564
1 968120 -1
1 358633 973
1 2321 0
1 331378 0
1 164889 583
1 70541 710
1 338259 54
1 866090 73
1 31800...

output:

0
17181559
15957501
15779114
115636303
15629732
17014614
15580821
149467817
73641596
15232651
15683692
16610143
17648378
143959447
15957501
340606826
16610143
16319403
138998203
18932628
16190551
272473588
15859079
16686342
17035952
16942975
279664809
246248740
230789370
299273468
16224182
17081451
...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 1346ms
memory: 256648kb

input:

200000 200050 2
1 528713629 1
1 213369548 -37822878
1 699166189 -474414180
1 77696830 1
1 113587245 1
1 416076134 1
1 439856442 -64939236
1 345132571 0
1 319809000 -58380052
1 118538123 -35192216
1 296406928 -50538228
1 937906349 0
1 812697276 -198448717
1 812963226 1
1 585375084 -485637384
1 891358...

output:

0
429570147481
371676672855
318706830834
478331382972
263557664319
370349057202
354356177314
257103023734
419025668238
253664150673
414860000299
265184541896
454101388044
368491773178
465943230853
341143189070
437236406813
338095814498
564203870191
254129964768
255221699111
419763751724
545110934986...

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 1412ms
memory: 252500kb

input:

200000 200049 777072
3 194540 779
4 448274 534
5 256933 0
3 796598 747
2 185663 221
3 303965 348
3 256210 0
5 841527 0
1 707797 263
5 627499 884
5 963924 0
5 85220 0
3 928652 899
1 62085 0
5 512144 0
2 727133 0
2 79884 0
5 400039 0
3 368172 0
4 521014 0
4 302255 57
1 138104 0
4 372879 47
2 562648 0
...

output:

0
20609231
194564
194663
194564
66834766
12475993
51218045
194564
112611815
194611
163554452
59812602
27049581
194564
194564
194611
194611
194611
211191723
194564
194611
43725196
194564
194611
48429938
194654
194611
37286113
194654
194564
28244990
194611
134326947
14069300
18531514
194540
194654
183...

result:

ok 200000 lines

Test #13:

score: 0
Accepted
time: 2199ms
memory: 250668kb

input:

200000 200048 925035
2 525947 32
11 183013 0
15 614707 0
8 76859 701
14 947804 192
2 467927 133
4 231061 224
9 737711 566
9 640793 0
1 845076 0
16 846825 0
1 21656 0
12 103091 797
12 135329 456
11 57259 0
14 203281 200
3 981455 0
2 972914 365
13 8562 546
8 634206 0
10 518153 0
3 636651 333
15 68339 ...

output:

0
766342
766342
766342
766342
3640272
766342
9816761
766342
4946763
766342
766342
5592035
766342
766342
766342
766342
5583544
6501478
766342
766342
11793421
766342
766342
766342
5143499
766342
766342
6850162
4813389
766342
766342
766342
10716690
1024184
766342
6503363
766342
4634956
13886721
766342
...

result:

ok 200000 lines

Test #14:

score: 0
Accepted
time: 2371ms
memory: 252932kb

input:

200000 200048 973201
33 847601 281
75 828865 0
79 697163 641
50 373713 140
24 630160 789
48 939829 370
47 588788 155
84 159402 293
47 617786 0
86 307415 347
71 943317 152
58 785204 0
84 152741 927
61 145251 780
56 441083 0
9 934387 351
98 589957 711
7 421074 0
99 334089 0
42 164529 0
97 13306 0
67 4...

output:

0
898102
898063
959085
898063
898063
898183
898063
898063
1030883
898063
1048507
898102
898063
898063
898063
898063
898063
1190439
898063
898063
899518
905305
898063
898063
974615
902855
1033513
935106
1582957
898063
898063
898063
898063
907926
898112
992408
898063
1012275
900484
898063
933881
89806...

result:

ok 200000 lines

Test #15:

score: -100
Time Limit Exceeded

input:

200000 200049 802175
434 897839 609
1637 128515 336
617 353368 0
1309 482860 0
658 923059 -1
266 917631 134
1425 651651 744
210 580125 0
1700 160241 0
60 699775 146
1005 273869 508
1182 814396 0
1159 668637 762
581 329891 0
386 782389 882
411 460313 0
208 466285 781
1408 917465 -1
227 911111 -1
1013...

output:


result: