Submission #17556
ソースコード
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 | #include<bits/stdc++.h> using namespace std; struct Node { int to, cost, wari; Node(){} Node( int to, int cost, int wari) : to(to), cost(cost), wari(wari) {} bool operator < ( const Node &a) const { return cost > a.cost; } }; int main() { int c, n, m, s, g; int a, b, f; cin>> c >> n >> m >> s >> g; vector<Node> node[101]; for ( int i = 0; i < m; i++) { cin>> a >> b >> f; node[a].push_back( Node(b, f, 0) ); node[b].push_back( Node(a, f, 0) ); node[a].push_back( Node(b, f / 2, 1) ); node[b].push_back( Node(a, f / 2, 1) ); } bool done[101][11] = {}; priority_queue<Node> que; que.push( Node(s, 0, c) ); while ( !que.empty() ) { Node q = que.top(); que.pop(); if ( done[q.to][q.wari] ) continue ; done[q.to][q.wari] = true ; if (q.to == g) { cout<< q.cost <<endl; break ; } for ( int i = 0; i < node[q.to].size(); i++) { if (node[q.to][i].wari) { if (q.wari > 0) que.push( Node(node[q.to][i].to, q.cost + node[q.to][i].cost, q.wari - 1) ); } else { que.push( Node(node[q.to][i].to, q.cost + node[q.to][i].cost, q.wari) ); } } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0717 - 高速バス |
ユーザー名 | ei1538 |
投稿日時 | 2017-05-15 17:00:43 |
言語 | C++11 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1312 Byte |
最大実行時間 | 37 ms |
最大メモリ使用量 | 780 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01.txt | AC | 12 ms | 476 KB |
1
|
input02.txt | AC | 15 ms | 408 KB |
1
|
input03.txt | AC | 13 ms | 488 KB |
1
|
input04.txt | AC | 37 ms | 548 KB |
1
|
input05.txt | AC | 12 ms | 608 KB |
1
|
input06.txt | AC | 14 ms | 628 KB |
1
|
input07.txt | AC | 10 ms | 676 KB |
1
|
input08.txt | AC | 14 ms | 780 KB |
1
|
input09.txt | AC | 13 ms | 664 KB |
1
|
input10.txt | AC | 10 ms | 576 KB |
1
|