UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202535#540. 免费yizhiming1004329ms64952kbC++1.6kb2024-02-16 07:51:132024-02-16 12:31:04

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
int read(){
	int x=0,f=1;char ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-'){f=-1;}ch = getchar();}
	while(ch>='0'&&ch<='9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}
const int N = 2e6+5;
int n,m,S,T,k;
int head[N],tote;
struct aa{
	int nxt,to,val;
}edge[N*4];
void link(int u,int v,int w){
	edge[++tote] = (aa){head[u],v,w};head[u] = tote;
}
int rk(int x,int y){
	return x+y*n;
}
struct bb{
	int u,val;
	bool operator<(const bb&x)const{
		return val>x.val;
	}
};
priority_queue<bb>q;
bool vis[N]; 
int dis[N];
void dij(){
	q.push((bb){S,0});
	for(int i=1;i<=(k+1)*n;i++){
		dis[i] = 1e9;
	}
	dis[S] = 0;
	while(!q.empty()){
		int u = q.top().u;
		q.pop();
		if(vis[u]){
			continue;
		}
		vis[u] = 1;
		for(int i=head[u];i;i=edge[i].nxt){
			int now = edge[i].to;
			if(dis[now]>dis[u]+edge[i].val){
				dis[now] = dis[u]+edge[i].val;
				q.push((bb){now,dis[now]});
			}
		}
	}
}
signed main(){
	n = read();m = read();S = read();T = read();k = read();
	while(m--){
		int u,v,w;
		u = read();v = read();w = read();
		for(int i=0;i<k;i++){
			link(rk(u,i),rk(v,i+1),0);
			link(rk(v,i),rk(u,i+1),0);
			link(rk(u,i),rk(v,i),w);
			link(rk(v,i),rk(u,i),w);
		}
		link(rk(u,k),rk(v,k),w);
		link(rk(v,k),rk(u,k),w);
	}
	dij();
//	for(int i=1;i<=n;i++){
//		for(int j=0;j<=k;j++){
//			cout<<dis[rk(i,j)]<<" ";
//		}
//		cout<<"\n";
//	}
	int ans = 1e9;
	for(int i=0;i<=k;i++){
		ans = min(ans,dis[rk(T,i)]);
	}
	cout<<ans<<"\n";
	return 0;
}

详细

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

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 434ms
memory: 61976kb

input:

644 1000 425 153 1000
1 2 140463
2 3 969586
2 4 402540
1 5 176573
4 6 860890
4 7 870045
4 8 509023
4...

output:

0

result:

ok "0"

Test #2:

score: 0
Accepted
time: 308ms
memory: 56368kb

input:

476 1000 213 301 1000
1 2 105998
1 3 624420
3 4 305716
4 5 182331
5 6 176444
5 7 31507
5 8 775109
5 ...

output:

0

result:

ok "0"

Test #3:

score: 0
Accepted
time: 390ms
memory: 63912kb

input:

864 1000 597 409 1000
1 2 18950
2 3 574149
1 4 465851
1 5 666564
5 6 131005
3 7 348191
3 8 139339
7 ...

output:

0

result:

ok "0"

Test #4:

score: 0
Accepted
time: 319ms
memory: 56508kb

input:

490 1000 256 162 1000
1 2 525741
2 3 271080
1 4 137739
3 5 156494
4 6 119881
6 7 664514
2 8 586756
5...

output:

0

result:

ok "0"

Test #5:

score: 0
Accepted
time: 386ms
memory: 63208kb

input:

784 1000 286 754 1000
1 2 633328
2 3 521673
2 4 752573
2 5 522253
3 6 410761
6 7 331174
3 8 426641
1...

output:

0

result:

ok "0"

Test #6:

score: 0
Accepted
time: 280ms
memory: 55724kb

input:

422 1000 210 277 1000
1 2 487208
1 3 224998
1 4 262451
3 5 461519
2 6 649350
3 7 780925
2 8 558476
1...

output:

0

result:

ok "0"

Test #7:

score: 0
Accepted
time: 219ms
memory: 54176kb

input:

224 1000 7 68 1000
1 2 851306
1 3 29349
3 4 70350
3 5 533327
1 6 300788
6 7 2114
5 8 575819
5 9 3193...

output:

0

result:

ok "0"

Test #8:

score: 0
Accepted
time: 209ms
memory: 54212kb

input:

227 1000 101 88 1000
1 2 46182
1 3 65425
1 4 906952
3 5 386722
3 6 387381
5 7 441955
4 8 369398
3 9 ...

output:

0

result:

ok "0"

Test #9:

score: 0
Accepted
time: 415ms
memory: 63768kb

input:

847 1000 381 456 1000
1 2 764714
1 3 783422
1 4 506476
4 5 743958
2 6 806574
4 7 766374
5 8 120231
2...

output:

0

result:

ok "0"

Test #10:

score: 0
Accepted
time: 467ms
memory: 64952kb

input:

982 1000 754 713 1000
1 2 797931
1 3 740185
3 4 728627
3 5 376427
1 6 168425
4 7 441955
1 8 516782
1...

output:

0

result:

ok "0"

Subtask #2:

score: 20
Accepted

Test #11:

score: 20
Accepted
time: 0ms
memory: 1268kb

input:

644 1000 425 153 0
1 2 140463
2 3 969586
2 4 402540
1 5 176573
4 6 860890
4 7 870045
4 8 509023
4 9 ...

output:

1593160

result:

ok "1593160"

Test #12:

score: 0
Accepted
time: 0ms
memory: 1268kb

input:

476 1000 213 301 0
1 2 105998
1 3 624420
3 4 305716
4 5 182331
5 6 176444
5 7 31507
5 8 775109
5 9 2...

output:

1881195

result:

ok "1881195"

Test #13:

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

input:

864 1000 597 409 0
1 2 18950
2 3 574149
1 4 465851
1 5 666564
5 6 131005
3 7 348191
3 8 139339
7 9 4...

output:

4813504

result:

ok "4813504"

Test #14:

score: 0
Accepted
time: 0ms
memory: 1264kb

input:

490 1000 256 162 0
1 2 525741
2 3 271080
1 4 137739
3 5 156494
4 6 119881
6 7 664514
2 8 586756
5 9 ...

output:

1548477

result:

ok "1548477"

Test #15:

score: 0
Accepted
time: 0ms
memory: 1264kb

input:

784 1000 286 754 0
1 2 633328
2 3 521673
2 4 752573
2 5 522253
3 6 410761
6 7 331174
3 8 426641
1 9 ...

output:

5172683

result:

ok "5172683"

Test #16:

score: 0
Accepted
time: 0ms
memory: 1264kb

input:

422 1000 210 277 0
1 2 487208
1 3 224998
1 4 262451
3 5 461519
2 6 649350
3 7 780925
2 8 558476
1 9 ...

output:

1650328

result:

ok "1650328"

Test #17:

score: 0
Accepted
time: 0ms
memory: 1264kb

input:

224 1000 7 68 0
1 2 851306
1 3 29349
3 4 70350
3 5 533327
1 6 300788
6 7 2114
5 8 575819
5 9 31935
5...

output:

42537

result:

ok "42537"

Test #18:

score: 0
Accepted
time: 0ms
memory: 1268kb

input:

227 1000 101 88 0
1 2 46182
1 3 65425
1 4 906952
3 5 386722
3 6 387381
5 7 441955
4 8 369398
3 9 155...

output:

671677

result:

ok "671677"

Test #19:

score: 0
Accepted
time: 0ms
memory: 1260kb

input:

847 1000 381 456 0
1 2 764714
1 3 783422
1 4 506476
4 5 743958
2 6 806574
4 7 766374
5 8 120231
2 9 ...

output:

5235960

result:

ok "5235960"

Test #20:

score: 0
Accepted
time: 0ms
memory: 1272kb

input:

982 1000 754 713 0
1 2 797931
1 3 740185
3 4 728627
3 5 376427
1 6 168425
4 7 441955
1 8 516782
1 9 ...

output:

7896193

result:

ok "7896193"

Subtask #3:

score: 70
Accepted

Test #21:

score: 70
Accepted
time: 0ms
memory: 1244kb

input:

1 1000 1 1 0
1 1 325325
1 1 460532
1 1 610307
1 1 382269
1 1 604230
1 1 422654
1 1 48701
1 1 145022
...

output:

0

result:

ok "0"

Test #22:

score: 0
Accepted
time: 2ms
memory: 1220kb

input:

2 1 2 1 0
1 2 819433

output:

819433

result:

ok "819433"

Test #23:

score: 0
Accepted
time: 0ms
memory: 1304kb

input:

20 1000 19 8 1
13 19 377424
11 13 735834
4 11 787697
9 4 212118
16 9 149405
3 16 495232
18 3 49455
1...

output:

471363

result:

ok "471363"

Test #24:

score: 0
Accepted
time: 0ms
memory: 1352kb

input:

50 1000 18 49 2
42 18 533662
14 42 83260
5 14 515495
17 5 383118
22 17 913368
38 22 784012
20 38 158...

output:

3302937

result:

ok "3302937"

Test #25:

score: 0
Accepted
time: 71ms
memory: 14432kb

input:

998 1000 323 176 233
285 323 960045
987 285 887361
762 987 971829
97 762 419676
141 97 563139
390 14...

output:

305304211

result:

ok "305304211"

Test #26:

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

input:

1000 1000 454 84 37
554 454 97482
570 554 406793
431 570 386698
383 431 745509
607 383 798937
713 60...

output:

466756626

result:

ok "466756626"

Test #27:

score: 0
Accepted
time: 0ms
memory: 1816kb

input:

1000 1000 658 924 10
105 658 1
27 105 1
311 27 1
702 311 1
217 702 1
130 217 1
88 130 1
319 88 1
329...

output:

989

result:

ok "989"

Test #28:

score: 0
Accepted
time: 495ms
memory: 60800kb

input:

1000 1000 620 131 998
364 620 258105
743 364 896437
276 743 401956
691 276 896195
934 691 698840
784...

output:

150

result:

ok "150"

Test #29:

score: 0
Accepted
time: 325ms
memory: 60916kb

input:

1000 1000 758 834 1000
555 758 44469
633 555 148140
197 633 728062
172 197 911720
705 172 700395
288...

output:

0

result:

ok "0"

Test #30:

score: 0
Accepted
time: 0ms
memory: 1252kb

input:

1000 1000 415 153 0
681 415 1000000
538 681 1000000
677 538 1000000
822 677 1000000
506 822 1000000
...

output:

999000000

result:

ok "999000000"