Submission #00009


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int64, int > Pi;
const int64 INF = 1LL << 60;
struct edge {
int to, cost;
};
vector< edge > graph[100000];
int main()
{
int N, M, C;
int64 ALL = 0;
cin >> N >> M >> C;
for(int i = 0; i < M; i++) {
int A, B, D;
cin >> A >> B >> D;
--A, --B;
graph[A].push_back((edge){B, D});
graph[B].push_back((edge){A, D});
ALL += D;
}
vector< Pi > min_cost(N);
for(int i = 0; i < N; i++) {
min_cost[i] = Pi(INF, i);
}
priority_queue< Pi, vector< Pi >, greater< Pi > > Que;
min_cost[0].first = 0;
Que.push(Pi(0, 0));
while(!Que.empty()) {
Pi p = Que.top(); Que.pop();
if(min_cost[p.second].first < p.first) continue;
for(auto e : graph[p.second]) {
int next = p.first + e.cost;
if(min_cost[e.to].first > next) {
min_cost[e.to].first = next;
Que.push(Pi(next, e.to));
}
}
}
sort(min_cost.begin(), min_cost.end());
bool used[100000] = {};
int ptr = 0;
int64 ret = INF;
while(ptr < N) {
do {
for(auto e : graph[min_cost[ptr].second]) {
if(used[e.to]) ALL -= e.cost;
}
used[min_cost[ptr].second] = true;
++ptr;
} while(min_cost[ptr - 1].first == min_cost[ptr].first);
ret = min(ret, ALL + 1LL * C * min_cost[ptr - 1].first);
}
cout << ret << endl;
}

ステータス

項目 データ
問題 0006 - JOI公園
ユーザー名 ei1333
投稿日時 2015-12-22 13:56:25
言語 C++11
状態 Wrong Answer
得点 60
ソースコード長 1450 Byte
最大実行時間 231 ms
最大メモリ使用量 12076 KB

セット

セット 得点 Cases
1 INPUT1 15 / 15 sample-*, 01-*
2 INPUT2 45 / 45 sample-*, 01-*, 02-*
3 INPUT3 0 / 40 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01-01.txt AC 22 ms 2908 KB
1
2
3
01-02.txt AC 21 ms 3136 KB
1
2
3
01-03.txt AC 17 ms 2976 KB
1
2
3
01-04.txt AC 24 ms 2940 KB
1
2
3
01-05.txt AC 22 ms 3028 KB
1
2
3
01-06.txt AC 15 ms 2996 KB
1
2
3
01-07.txt AC 18 ms 2956 KB
1
2
3
01-08.txt AC 21 ms 2924 KB
1
2
3
01-09.txt AC 20 ms 3012 KB
1
2
3
01-10.txt AC 18 ms 2980 KB
1
2
3
01-11.txt AC 20 ms 2936 KB
1
2
3
01-12.txt AC 20 ms 3028 KB
1
2
3
01-13.txt AC 22 ms 3112 KB
1
2
3
01-14.txt AC 22 ms 3200 KB
1
2
3
01-15.txt AC 21 ms 3024 KB
1
2
3
01-16.txt AC 18 ms 3116 KB
1
2
3
01-17.txt AC 21 ms 3076 KB
1
2
3
01-18.txt AC 15 ms 3036 KB
1
2
3
02-01.txt AC 20 ms 2996 KB
2
3
02-02.txt AC 22 ms 2968 KB
2
3
02-03.txt AC 19 ms 3060 KB
2
3
02-04.txt AC 20 ms 3140 KB
2
3
02-05.txt AC 24 ms 3008 KB
2
3
02-06.txt AC 22 ms 2972 KB
2
3
02-07.txt AC 23 ms 3060 KB
2
3
02-08.txt AC 17 ms 3152 KB
2
3
02-09.txt AC 22 ms 3264 KB
2
3
02-10.txt AC 20 ms 3120 KB
2
3
02-11.txt AC 18 ms 2972 KB
2
3
02-12.txt AC 19 ms 2936 KB
2
3
02-13.txt AC 22 ms 3024 KB
2
3
02-14.txt AC 22 ms 3080 KB
2
3
02-15.txt AC 20 ms 2928 KB
2
3
02-16.txt AC 23 ms 3016 KB
2
3
02-17.txt AC 24 ms 3084 KB
2
3
02-18.txt AC 20 ms 3272 KB
2
3
02-19.txt AC 24 ms 3124 KB
2
3
03-01.txt AC 158 ms 9872 KB
3
03-02.txt AC 220 ms 11708 KB
3
03-03.txt AC 53 ms 5276 KB
3
03-04.txt AC 170 ms 10172 KB
3
03-05.txt AC 108 ms 10656 KB
3
03-06.txt AC 97 ms 10612 KB
3
03-07.txt WA 113 ms 7632 KB
3
03-08.txt WA 112 ms 7648 KB
3
03-09.txt AC 215 ms 11888 KB
3
03-10.txt AC 119 ms 8684 KB
3
03-11.txt AC 222 ms 11840 KB
3
03-12.txt AC 218 ms 11968 KB
3
03-13.txt AC 231 ms 12004 KB
3
03-14.txt AC 223 ms 12036 KB
3
03-15.txt AC 224 ms 11944 KB
3
03-16.txt AC 216 ms 11972 KB
3
03-17.txt AC 215 ms 12004 KB
3
03-18.txt AC 219 ms 12044 KB
3
03-19.txt AC 214 ms 12076 KB
3
sample-01.txt AC 20 ms 3156 KB
1
2
3
sample-02.txt AC 20 ms 3128 KB
1
2
3
sample-03.txt AC 21 ms 3224 KB
1
2
3