Submission #00010


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long int64;
typedef pair< int64, int > Pi;
const int64 INF = 1LL << 60;
struct edge {
int to, cost;
};
vector< edge > graph[100000];
signed 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:47
言語 C++11
状態 Accepted
得点 100
ソースコード長 1476 Byte
最大実行時間 242 ms
最大メモリ使用量 16252 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
01-01.txt AC 23 ms 2908 KB
1
2
3
01-02.txt AC 21 ms 3012 KB
1
2
3
01-03.txt AC 21 ms 2988 KB
1
2
3
01-04.txt AC 18 ms 2960 KB
1
2
3
01-05.txt AC 22 ms 2920 KB
1
2
3
01-06.txt AC 25 ms 3012 KB
1
2
3
01-07.txt AC 21 ms 2840 KB
1
2
3
01-08.txt AC 23 ms 2800 KB
1
2
3
01-09.txt AC 16 ms 3016 KB
1
2
3
01-10.txt AC 19 ms 2980 KB
1
2
3
01-11.txt AC 19 ms 3060 KB
1
2
3
01-12.txt AC 25 ms 3024 KB
1
2
3
01-13.txt AC 23 ms 2980 KB
1
2
3
01-14.txt AC 19 ms 3068 KB
1
2
3
01-15.txt AC 16 ms 3152 KB
1
2
3
01-16.txt AC 20 ms 3112 KB
1
2
3
01-17.txt AC 17 ms 2940 KB
1
2
3
01-18.txt AC 20 ms 3020 KB
1
2
3
02-01.txt AC 17 ms 2972 KB
2
3
02-02.txt AC 20 ms 2928 KB
2
3
02-03.txt AC 20 ms 3016 KB
2
3
02-04.txt AC 22 ms 3216 KB
2
3
02-05.txt AC 20 ms 3004 KB
2
3
02-06.txt AC 25 ms 2960 KB
2
3
02-07.txt AC 28 ms 3048 KB
2
3
02-08.txt AC 21 ms 3268 KB
2
3
02-09.txt AC 18 ms 3276 KB
2
3
02-10.txt AC 27 ms 3152 KB
2
3
02-11.txt AC 25 ms 3036 KB
2
3
02-12.txt AC 20 ms 3128 KB
2
3
02-13.txt AC 20 ms 3084 KB
2
3
02-14.txt AC 27 ms 3248 KB
2
3
02-15.txt AC 23 ms 3108 KB
2
3
02-16.txt AC 18 ms 3196 KB
2
3
02-17.txt AC 19 ms 3260 KB
2
3
02-18.txt AC 23 ms 3416 KB
2
3
02-19.txt AC 23 ms 3408 KB
2
3
03-01.txt AC 171 ms 13000 KB
3
03-02.txt AC 230 ms 15672 KB
3
03-03.txt AC 54 ms 5860 KB
3
03-04.txt AC 171 ms 14256 KB
3
03-05.txt AC 107 ms 12308 KB
3
03-06.txt AC 99 ms 12384 KB
3
03-07.txt AC 106 ms 9916 KB
3
03-08.txt AC 105 ms 9864 KB
3
03-09.txt AC 229 ms 15956 KB
3
03-10.txt AC 121 ms 10044 KB
3
03-11.txt AC 220 ms 16028 KB
3
03-12.txt AC 242 ms 16012 KB
3
03-13.txt AC 227 ms 16028 KB
3
03-14.txt AC 233 ms 16048 KB
3
03-15.txt AC 226 ms 16196 KB
3
03-16.txt AC 237 ms 16232 KB
3
03-17.txt AC 222 ms 16252 KB
3
03-18.txt AC 228 ms 16032 KB
3
03-19.txt AC 228 ms 16044 KB
3
sample-01.txt AC 19 ms 3128 KB
1
2
3
sample-02.txt AC 21 ms 3096 KB
1
2
3
sample-03.txt AC 19 ms 3068 KB
1
2
3