UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189233#3321. 飞翔(fly)Harry27182100833ms2388kbC++11997b2023-10-04 09:19:522023-10-04 12:57:14

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,dis[505][505],dp[505],tmp[505];
struct edge{int u,v,w;}e[125005];
bool cmp(edge x,edge y){return x.w>y.w;}
void cmin(int &x,int y){x=(x<y?x:y);}
int main()
{
	//freopen("fly.in","r",stdin);
	//freopen("fly.out","w",stdout);
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dis[i][j]=0x3f3f3f3f;
    for(int i=1;i<=n;i++)dis[i][i]=0;
    for(int i=1;i<=m;i++)
	{
		cin>>e[i].u>>e[i].v>>e[i].w;
		dis[e[i].u][e[i].v]=dis[e[i].v][e[i].u]=1;
	}
	for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cmin(dis[i][j],dis[i][k]+dis[k][j]);
	sort(e+1,e+m+1,cmp);
	dp[1]=0;for(int i=2;i<=n;i++)dp[i]=0x3f3f3f3f;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)tmp[j]=dp[j];
		int u=e[i].u,v=e[i].v;
		for(int j=1;j<=n;j++)cmin(dp[j],tmp[u]+e[i].w+e[i].w*dis[v][j]);
		for(int j=1;j<=n;j++)cmin(dp[j],tmp[v]+e[i].w+e[i].w*dis[u][j]);
	}
	cout<<dp[n];
	return 0;
}

Details

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

Test #1:

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

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: 1320kb

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: 1316kb

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: 125ms
memory: 2368kb

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: 125ms
memory: 2372kb

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: 113ms
memory: 2284kb

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: 113ms
memory: 2280kb

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: 109ms
memory: 2280kb

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: 122ms
memory: 2388kb

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: 126ms
memory: 2388kb

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