Submission #00148


ソースコード

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define INF (1<<24)
typedef pair<int,int> P;
typedef pair<int,P> Pi;
vector<P> edge[811];
int min_cost[811];
int min_cost2[811];
int N,M,S,G;
int solve(int cost){
priority_queue<Pi,vector<Pi>,greater<Pi> > que;
que.push(Pi(cost,P(0,G)));
int ans = INF;
for(int i=0;i<811;i++){
min_cost2[i] = INF;
}
while(!que.empty()){
Pi p = que.top(); que.pop();
int ncost = p.first;
int homo = p.second.first;
int now = p.second.second;
if(now == S && ncost == cost*2){
ans = min(ans,homo);
}
if(min_cost2[now] < ncost) continue;
min_cost2[now] = ncost;
for(int i=0;i<edge[now].size();i++){
P pi = edge[now][i];
int next = pi.first;
int nc = pi.second;
int add = 0;
if(min_cost[next] != -1){
add = (ncost+nc)-min_cost[next];
}
que.push(Pi(ncost+nc,P(homo+add,next)));
}
}
return ans;
}
int main(){
cin >> N >> M >> S >> G;
for(int i=0;i<M;i++){
int a,b,c;
cin >> a >> b >> c;
edge[a].push_back(P(b,c));
edge[b].push_back(P(a,c));
}
for(int i=0;i<811;i++){
min_cost[i] = INF;
min_cost2[i] = INF;
}
int homo = INF;
priority_queue<P,vector<P>,greater<P> > que;
que.push(P(0,S));
min_cost[1] = 0;
int flg = 0;
while(!que.empty()){
P p = que.top(); que.pop();
int cost = p.first;
int now = p.second;
if(min_cost[now] < cost) continue;
if(now == G) {
homo = min(homo,solve(cost));
flg = 1;
}
min_cost[now] = cost;
for(int i=0;i<edge[now].size();i++){
P pi = edge[now][i];
int next = pi.first;
int nc = pi.second;
que.push(P(cost+nc,next));
}
}
if(flg == 0) cout << "Homoed." << endl;
else cout << homo << " " << min_cost[G] << endl;
}

ステータス

項目 データ
問題 0008 - Mission : ホモへの堕落を回避せよ
ユーザー名 ei1428
投稿日時 2016-05-14 16:07:47
言語 C++11
状態 Wrong Answer
得点 0
ソースコード長 1906 Byte
最大実行時間 22 ms
最大メモリ使用量 1520 KB

セット

セット 得点 Cases
1 ALL 0 / 14 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 16 ms 604 KB
1
in2.txt AC 14 ms 868 KB
1
in3.txt AC 16 ms 760 KB
1
in4.txt WA 16 ms 892 KB
1
in5.txt AC 17 ms 1160 KB
1
in6.txt AC 18 ms 1200 KB
1
in7.txt AC 22 ms 1520 KB
1
in8.txt AC 21 ms 1172 KB
1
in9.txt AC 15 ms 448 KB
1
in10.txt AC 15 ms 536 KB
1
in11.txt AC 13 ms 504 KB
1
in12.txt AC 13 ms 728 KB
1
in13.txt AC 15 ms 828 KB
1
in14.txt AC 16 ms 840 KB
1
in15.txt AC 15 ms 872 KB
1
in16.txt AC 19 ms 956 KB
1
in17.txt AC 16 ms 900 KB
1
in18.txt WA 19 ms 1080 KB
1
in19.txt AC 19 ms 1156 KB
1
in20.txt AC 18 ms 884 KB
1