Submission #00007


ソースコード

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 << 55;
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:55:49
言語 C++11
状態 Wrong Answer
得点 60
ソースコード長 1450 Byte
最大実行時間 231 ms
最大メモリ使用量 12084 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01-01.txt AC 25 ms 2908 KB
1
2
3
01-02.txt AC 26 ms 2876 KB
1
2
3
01-03.txt AC 20 ms 2968 KB
1
2
3
01-04.txt AC 16 ms 2932 KB
1
2
3
01-05.txt AC 22 ms 2896 KB
1
2
3
01-06.txt AC 17 ms 2868 KB
1
2
3
01-07.txt AC 20 ms 2956 KB
1
2
3
01-08.txt AC 20 ms 3036 KB
1
2
3
01-09.txt AC 25 ms 3000 KB
1
2
3
01-10.txt AC 18 ms 2968 KB
1
2
3
01-11.txt AC 27 ms 2928 KB
1
2
3
01-12.txt AC 21 ms 2896 KB
1
2
3
01-13.txt AC 17 ms 2980 KB
1
2
3
01-14.txt AC 18 ms 2812 KB
1
2
3
01-15.txt AC 16 ms 3032 KB
1
2
3
01-16.txt AC 24 ms 3120 KB
1
2
3
01-17.txt AC 21 ms 3084 KB
1
2
3
01-18.txt AC 26 ms 3044 KB
1
2
3
02-01.txt AC 18 ms 3004 KB
2
3
02-02.txt AC 17 ms 2844 KB
2
3
02-03.txt AC 18 ms 3068 KB
2
3
02-04.txt AC 23 ms 3148 KB
2
3
02-05.txt AC 19 ms 3024 KB
2
3
02-06.txt AC 15 ms 3112 KB
2
3
02-07.txt AC 16 ms 2944 KB
2
3
02-08.txt AC 21 ms 3160 KB
2
3
02-09.txt AC 17 ms 3148 KB
2
3
02-10.txt AC 21 ms 3128 KB
2
3
02-11.txt AC 20 ms 2984 KB
2
3
02-12.txt AC 21 ms 3080 KB
2
3
02-13.txt AC 18 ms 3036 KB
2
3
02-14.txt AC 24 ms 3096 KB
2
3
02-15.txt AC 19 ms 3072 KB
2
3
02-16.txt AC 22 ms 3028 KB
2
3
02-17.txt AC 22 ms 3100 KB
2
3
02-18.txt AC 25 ms 3284 KB
2
3
02-19.txt AC 18 ms 3252 KB
2
3
03-01.txt AC 171 ms 10004 KB
3
03-02.txt AC 210 ms 11712 KB
3
03-03.txt AC 58 ms 5284 KB
3
03-04.txt AC 181 ms 10180 KB
3
03-05.txt AC 118 ms 10668 KB
3
03-06.txt AC 84 ms 10884 KB
3
03-07.txt WA 113 ms 7904 KB
3
03-08.txt WA 136 ms 7920 KB
3
03-09.txt AC 218 ms 12032 KB
3
03-10.txt AC 113 ms 8832 KB
3
03-11.txt AC 230 ms 11984 KB
3
03-12.txt AC 231 ms 11980 KB
3
03-13.txt AC 226 ms 12012 KB
3
03-14.txt AC 221 ms 11920 KB
3
03-15.txt AC 224 ms 11960 KB
3
03-16.txt AC 227 ms 11984 KB
3
03-17.txt AC 224 ms 11888 KB
3
03-18.txt AC 231 ms 12052 KB
3
03-19.txt AC 219 ms 12084 KB
3
sample-01.txt AC 23 ms 3160 KB
1
2
3
sample-02.txt AC 24 ms 3136 KB
1
2
3
sample-03.txt AC 18 ms 3228 KB
1
2
3