UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189257#3321. 飞翔(fly)Alan_Zhaoyz100837ms3252kbC++111.1kb2023-10-04 09:34:362023-10-04 12:58:02

answer

#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
const int N=505;
int n,m,g[N][N],dis[N][N],dis2[N],vis[N];
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>m;
	memset(g,0x3f,sizeof(g));
	For(i,1,m){
		int u,v,w;
		cin>>u>>v>>w;
		g[u][v]=min(g[u][v],w);
		g[v][u]=min(g[v][u],w);
	}
	memset(dis,0x3f,sizeof(dis));
	For(i,1,n){
		For(j,1,n){
			if(g[i][j]<1e9){
				dis[i][j]=1;
			}
		}
		dis[i][i]=0;
	}
	For(k,1,n){
		For(i,1,n){
			For(j,1,n){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	memset(dis2,0x3f,sizeof(dis2));
	dis2[1]=0;
	For(_,1,n){
		int u=0;
		For(i,1,n){
			if(!vis[i]&&(!u||dis2[i]<dis2[u])){
				u=i;
			}
		}
		if(!u) break;
		vis[u]=1;
		For(v,1,n){
			if(g[u][v]<1e9){
				For(x,1,n){
					if(dis[v][x]<1e9){
						dis2[x]=min(dis2[x],dis2[u]+g[u][v]*(dis[v][x]+1));
					}
				}
			}
		}
	}
	cout<<dis2[n]<<'\n';
	return 0;
}

Details

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 3244kb

input:

20 40
1 2 690537
1 3 798286
2 4 984879
1 5 908148
3 6 891923
2 7 987330
5 8 978098
8 9 965037
8 10 6...

output:

807192

result:

ok single line: '807192'

Test #2:

score: 10
Accepted
time: 0ms
memory: 3244kb

input:

20 40
1 2 862239
2 3 697878
2 4 905713
1 5 710051
2 6 797312
2 7 702054
7 8 884083
7 9 786004
7 10 9...

output:

2373055

result:

ok single line: '2373055'

Test #3:

score: 10
Accepted
time: 0ms
memory: 3244kb

input:

20 40
1 2 876614
1 3 968907
3 4 860017
3 5 867995
5 6 713757
6 7 684056
4 8 928248
5 9 775400
7 10 8...

output:

1657179

result:

ok single line: '1657179'

Test #4:

score: 10
Accepted
time: 126ms
memory: 3252kb

input:

500 10000
1 2 1
1 3 1
3 4 1
1 5 1
4 6 1
3 7 1
6 8 1
8 9 1
9 10 1
9 11 1
9 12 1
11 13 1
9 14 1
14 15 ...

output:

2

result:

ok single line: '2'

Test #5:

score: 10
Accepted
time: 126ms
memory: 3252kb

input:

500 10000
1 2 1
2 3 1
3 4 1
1 5 1
4 6 1
6 7 1
6 8 1
8 9 1
8 10 1
10 11 1
7 12 1
8 13 1
13 14 1
12 15...

output:

2

result:

ok single line: '2'

Test #6:

score: 10
Accepted
time: 111ms
memory: 3248kb

input:

500 1000
1 2 923284
1 3 807610
1 4 869360
4 5 911570
2 6 733380
2 7 686639
6 8 704538
4 9 769480
7 1...

output:

4010302

result:

ok single line: '4010302'

Test #7:

score: 10
Accepted
time: 107ms
memory: 3248kb

input:

500 1000
1 2 947043
2 3 806915
3 4 670021
1 5 939043
2 6 788696
6 7 670515
3 8 889488
5 9 925621
8 1...

output:

4135596

result:

ok single line: '4135596'

Test #8:

score: 10
Accepted
time: 111ms
memory: 3248kb

input:

500 1000
1 2 940294
1 3 724108
3 4 774175
2 5 749134
3 6 814752
5 7 695034
5 8 968937
5 9 785345
7 1...

output:

5633972

result:

ok single line: '5633972'

Test #9:

score: 10
Accepted
time: 126ms
memory: 3248kb

input:

500 10000
1 2 876406
2 3 883210
2 4 818771
4 5 871755
3 6 709535
3 7 858204
7 8 732881
5 9 846857
8 ...

output:

1348166

result:

ok single line: '1348166'

Test #10:

score: 10
Accepted
time: 130ms
memory: 3248kb

input:

500 10000
1 2 777746
1 3 879140
3 4 813644
4 5 815532
5 6 951477
5 7 960811
5 8 727228
8 9 920934
6 ...

output:

1481760

result:

ok single line: '1481760'

Extra Test:

score: 0
Extra Test Passed