Submission #34598
ソースコード
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 82 83 84 85 86 87 88 89 90 | #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; #define pb emplace_back #define fi first #define se second #define outl(x) cout << (x) << '\n' #define rep(i,n) for(int i=0; i<(n); ++i) template < class A, class B> inline bool chmin(A &a, B b){ return b<a ? a=b,1 : 0;} typedef long long ll; typedef pair< int , int > pii; constexpr int INF = 0x3f3f3f3f; int c, N, M; vector<pii> G[102]; int mcos[102][12]; inline int slv( int , int ); void dijkstra( int ); signed main() { int s, g; cin.tie(0), ios::sync_with_stdio( false ); cin >> c >> N >> M >> s >> g; rep(i, M) { int s, t, c; cin >> s >> t >> c; G[s].pb(pii(c,t)); G[t].pb(pii(c,s)); } outl(slv(s,g)); } struct Edge { int node, cost, cnt; Edge( int a=0, int b=0, int c=0): node(a), cost(b), cnt(c) {} bool operator < ( const Edge &rhs) const { return (cost < rhs.cost); } bool operator > ( const Edge &rhs) const { return (cost > rhs.cost); } }; void dijkstra( int s) { priority_queue< Edge, vector<Edge>, greater<Edge> > pq; pq.emplace(Edge(s,0,0)); memset (mcos, INF, sizeof (mcos)); mcos[s][0] = 0; while (pq.size()) { const Edge &now = pq.top(); const int u=now.node, cost=now.cost, cnt=now.cnt; pq.pop(); if (mcos[u][cnt] < cost) continue ; for ( const auto &e : G[u]) { const int nxt = e.se; if (cnt < c) { const int nc = e.fi/2 + cost; if (chmin(mcos[nxt][cnt+1], nc)) { pq.emplace(Edge(nxt, nc, cnt+1)); } } const int nc = e.fi + cost; if (chmin(mcos[nxt][cnt], nc)) { pq.emplace(Edge(nxt, nc, cnt)); } } } } inline int slv( int s, int g) { dijkstra(s); int ans = INF; for ( int i=0; i<=c; ++i) { ans = min(ans, mcos[g][i]); } return ans; } |
ステータス
項目 | データ |
---|---|
問題 | 0717 - 高速バス |
ユーザー名 | Arumakan_ei1727 |
投稿日時 | 2018-05-03 10:20:04 |
言語 | C++11 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 2116 Byte |
最大実行時間 | 48 ms |
最大メモリ使用量 | 696 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01.txt | AC | 31 ms | 480 KB |
1
|
input02.txt | AC | 25 ms | 536 KB |
1
|
input03.txt | AC | 18 ms | 480 KB |
1
|
input04.txt | AC | 48 ms | 540 KB |
1
|
input05.txt | AC | 21 ms | 584 KB |
1
|
input06.txt | AC | 30 ms | 624 KB |
1
|
input07.txt | AC | 20 ms | 544 KB |
1
|
input08.txt | AC | 25 ms | 696 KB |
1
|
input09.txt | AC | 21 ms | 588 KB |
1
|
input10.txt | AC | 22 ms | 644 KB |
1
|