Submission #00374


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define INF 999999
#define ROOP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int N,M,A,B,prev[3000][3000],G[3000][3000];
long long ans=0;
int sp=0,stack[3000];
void warshall_froyd(){
ROOP(i,N){
ROOP(j,N){
prev[i][j]=i;
}
}
ROOP(k,N){
ROOP(i,N){
ROOP(j,N){
if(G[i][j]>G[i][k]+G[k][j]){
G[i][j]=G[i][k]+G[k][j];
prev[i][j]=prev[k][j];
}
}
}
}
}
void get_path(int s,int g){
for(int cur=g;cur!=s;cur=prev[s][cur]){
stack[sp++]=cur;
}
stack[sp++]=s;
}
int main(){
scanf("%d %d %d %d",&N,&M,&A,&B);
ROOP(i,N) ROOP(j,N) G[i][j]=INF;
ROOP(i,N) G[i][i]=0;
ROOP(i,M){
int u,v,t;
scanf(" %d %d %d",&u,&v,&t);
G[u][v]=t;G[v][u]=t;
}
warshall_froyd();
get_path(A,B);
ROOP(i,N){
int MIN=INF;
for(int j=0;j<sp;j++){
MIN=min(MIN,G[i][stack[j]]);
}
ans+=MIN;
}
printf("%lld\n",ans);
return 0;
}

ステータス

項目 データ
問題 0004 - railway
ユーザー名 nii
投稿日時 2017-11-26 14:55:43
言語 C++
状態 Wrong Answer
得点 0
ソースコード長 1056 Byte
最大実行時間 1000 ms
最大メモリ使用量 65536 KB

セット

セット 得点 Cases
1 ALL 0 / 80 *
2 partial_1 0 / 20 !*, *S*

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
!test01.txt AC 16 ms 2524 KB
1
2
!test02.txt AC 17 ms 2468 KB
1
2
mesh_01.txt WA 706 ms 24276 KB
1
mesh_02.txt WA 693 ms 24284 KB
1
randomL_01.txt MLE 1000 ms 65536 KB
1
randomL_02.txt MLE 454 ms 65536 KB
1
randomL_03.txt MLE 798 ms 65536 KB
1
randomL_04.txt MLE 457 ms 65536 KB
1
randomL_05.txt MLE 511 ms 65536 KB
1
randomS_01.txt WA 674 ms 25376 KB
1
2
randomS_02.txt WA 636 ms 25384 KB
1
2
randomS_03.txt WA 620 ms 25516 KB
1
2
treeL_01.txt MLE 341 ms 65536 KB
1
treeL_02.txt MLE 446 ms 65536 KB
1
treeS_01.txt AC 733 ms 24500 KB
1
2
treeS_02.txt WA 662 ms 24508 KB
1
2