UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#207064#3703. 第 k 短路Josephcheng1003007ms10256kbC++111.0kb2024-07-26 19:56:292024-07-26 20:21:37

answer

#include<bits/stdc++.h>
#define LL long long
#define N 200005

using namespace std;

struct node
{
	LL a,b,c;
	bool operator < (const node &a) const
	{
		return c<a.c;
	}
}e1[N];

unordered_map<LL,LL> st,st2;
LL n,m,k,u,v,w,pos,tot;
LL head[10005],seq[N];
LL dis[605][605];

int main()
{
	memset(dis,0x3f,sizeof dis);
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=m;i++)
		scanf("%lld%lld%lld",&e1[i].a,&e1[i].b,&e1[i].c);
	sort(e1+1,e1+m+1);
	for(int i=1;i<=k;i++){
		u=e1[i].a,v=e1[i].b,w=e1[i].c;
		if(st[u]==0) st[u]=++tot;
		if(st[v]==0) st[v]=++tot;
		st2[st[u]]=u,st2[st[v]]=v;
		u=st[u],v=st[v];
		dis[u][v]=dis[v][u]=w;
//		printf("%d %d:%d\n",st2[u],st2[v],dis[u][v]);
	}
	n=tot;
//	for(int i=1;i<=n;i++)
//		dis[i][i]=0;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			seq[++pos]=dis[i][j];
	sort(seq+1,seq+pos+1);
	printf("%lld",seq[k]);
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 4116kb

input:

20 60 190
19 3 546376034
4 18 642274955
16 4 414081357
12 16 640525065
16 19 527988394
18 16 8720426...

output:

2109840819

result:

ok "2109840819"

Test #2:

score: 5
Accepted
time: 0ms
memory: 4112kb

input:

20 60 190
14 19 258517624
5 14 561725429
17 13 804524582
10 13 970111976
10 9 654402387
14 6 2743447...

output:

1654217400

result:

ok "1654217400"

Test #3:

score: 5
Accepted
time: 0ms
memory: 4116kb

input:

20 60 190
2 14 892071621
17 6 61309720
14 7 500404604
10 4 437343162
18 7 697908122
11 13 328217219
...

output:

1379186768

result:

ok "1379186768"

Test #4:

score: 5
Accepted
time: 0ms
memory: 4160kb

input:

300 1000 33
68 153 965194295
269 59 776134907
228 268 442872850
280 38 91554317
139 18 671966769
126...

output:

33954960

result:

ok "33954960"

Test #5:

score: 5
Accepted
time: 17ms
memory: 4408kb

input:

300 1000 284
211 90 282205285
67 41 261259454
59 268 505521082
255 75 200658225
8 123 954193932
89 1...

output:

159060151

result:

ok "159060151"

Test #6:

score: 5
Accepted
time: 0ms
memory: 4160kb

input:

300 1000 32
215 253 309063273
179 146 880209828
245 228 697316105
118 135 642848836
223 157 14636240...

output:

23171242

result:

ok "23171242"

Test #7:

score: 5
Accepted
time: 119ms
memory: 8996kb

input:

100000 200000 103
31127 47073 803487347
72287 7289 44509230
68404 4500 472507029
59566 68309 7758282...

output:

530575

result:

ok "530575"

Test #8:

score: 5
Accepted
time: 102ms
memory: 8808kb

input:

100000 200000 17
63730 15201 884090851
78370 54279 463681993
63041 1788 413954829
99506 33814 156262...

output:

76532

result:

ok "76532"

Test #9:

score: 5
Accepted
time: 191ms
memory: 9392kb

input:

100000 200000 189
86524 21341 205700739
41630 45875 181098806
12351 24722 236668794
89930 26760 1599...

output:

880325

result:

ok "880325"

Test #10:

score: 5
Accepted
time: 127ms
memory: 9040kb

input:

100000 200000 118
58217 25921 569722300
13400 53703 948055398
54451 33374 524577274
47464 92480 5571...

output:

560954

result:

ok "560954"

Test #11:

score: 5
Accepted
time: 187ms
memory: 9276kb

input:

100000 200000 170
32537 97355 28791331
17769 13567 856590740
17453 20823 139013738
40442 35479 82101...

output:

887965

result:

ok "887965"

Test #12:

score: 5
Accepted
time: 132ms
memory: 9060kb

input:

100000 200000 123
17540 12890 910405130
15199 19152 344644180
98868 16103 871331395
19045 1705 53689...

output:

674664

result:

ok "674664"

Test #13:

score: 5
Accepted
time: 393ms
memory: 9964kb

input:

100000 200000 269
38835 57264 187298504
48125 66699 366204205
24161 47949 89029999
98780 56630 59841...

output:

1350380

result:

ok "1350380"

Test #14:

score: 5
Accepted
time: 296ms
memory: 9720kb

input:

100000 200000 236
9324 49939 252896977
21187 17793 119469066
89089 25846 35811071
49359 77068 350672...

output:

1061679

result:

ok "1061679"

Test #15:

score: 5
Accepted
time: 125ms
memory: 8996kb

input:

100000 200000 105
53269 47801 447374290
3372 77840 353130018
43082 55561 362410570
48726 57099 14375...

output:

574030

result:

ok "574030"

Test #16:

score: 5
Accepted
time: 95ms
memory: 8956kb

input:

100000 200000 96
33148 6381 259642109
73667 39395 24575800
17814 16904 241662104
96993 89375 4482562...

output:

474618

result:

ok "474618"

Test #17:

score: 5
Accepted
time: 100ms
memory: 8852kb

input:

100000 200000 49
91727 3014 888565189
81934 79378 555794317
11841 55748 229421194
9938 43597 1391756...

output:

235488

result:

ok "235488"

Test #18:

score: 5
Accepted
time: 145ms
memory: 9088kb

input:

100000 200000 130
50566 89219 627637617
15093 11865 113154491
84372 88335 131584020
64398 80202 5489...

output:

667491

result:

ok "667491"

Test #19:

score: 5
Accepted
time: 462ms
memory: 7900kb

input:

100000 99999 300
68089 24272 701104429
70394 4724 687800626
6013 52987 585252332
9472 22214 89144412...

output:

2792395

result:

ok "2792395"

Test #20:

score: 5
Accepted
time: 516ms
memory: 10256kb

input:

200000 199999 300
40819 49856 378013260
51864 64292 354262253
87187 61853 297726992
185234 131834 62...

output:

1533821

result:

ok "1533821"