結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | kappybar |
提出日時 | 2020-11-27 22:53:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,944 bytes |
コンパイル時間 | 2,448 ms |
コンパイル使用メモリ | 193,592 KB |
実行使用メモリ | 32,736 KB |
最終ジャッジ日時 | 2024-07-26 20:07:32 |
合計ジャッジ時間 | 16,963 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
8,640 KB |
testcase_01 | AC | 5 ms
8,728 KB |
testcase_02 | WA | - |
testcase_03 | AC | 361 ms
27,892 KB |
testcase_04 | AC | 406 ms
30,172 KB |
testcase_05 | AC | 423 ms
32,736 KB |
testcase_06 | AC | 376 ms
28,464 KB |
testcase_07 | AC | 385 ms
29,488 KB |
testcase_08 | AC | 370 ms
28,080 KB |
testcase_09 | AC | 367 ms
27,436 KB |
testcase_10 | WA | - |
testcase_11 | AC | 398 ms
28,988 KB |
testcase_12 | AC | 387 ms
29,060 KB |
testcase_13 | AC | 408 ms
30,496 KB |
testcase_14 | AC | 356 ms
27,352 KB |
testcase_15 | AC | 364 ms
28,472 KB |
testcase_16 | AC | 417 ms
30,060 KB |
testcase_17 | AC | 419 ms
30,676 KB |
testcase_18 | AC | 378 ms
28,968 KB |
testcase_19 | AC | 369 ms
28,500 KB |
testcase_20 | AC | 351 ms
27,836 KB |
testcase_21 | AC | 406 ms
30,256 KB |
testcase_22 | AC | 376 ms
28,192 KB |
testcase_23 | AC | 414 ms
30,540 KB |
testcase_24 | AC | 362 ms
28,392 KB |
testcase_25 | AC | 410 ms
29,932 KB |
testcase_26 | AC | 386 ms
29,568 KB |
testcase_27 | AC | 383 ms
29,064 KB |
testcase_28 | AC | 392 ms
29,616 KB |
testcase_29 | WA | - |
testcase_30 | AC | 409 ms
29,872 KB |
testcase_31 | AC | 402 ms
29,812 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 412 ms
31,092 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)); #define chmax(x,y) x = max((x),(y)); using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; int n = 100005; int m; vector<map<ll,ll>> graph(n); using p = pair<pll,int>; vector<ll> before(n); vector<ll> Dijkstra(int start){ vector<bool> seen(n,false); vector<ll> shortest(n,LINF); priority_queue<p,vector<p>,greater<p>> pq; pq.push(p(pll{0,start},-1)); while(!pq.empty()){ ll dist = pq.top().first.first; int node = pq.top().first.second; int b = pq.top().second; pq.pop(); if(seen[node]) continue; shortest[node] = dist; before[node] = b; seen[node] = true; for(auto next:graph[node]){ int next_node = next.first; ll next_cost = next.second; if(seen[next_node]) continue; pq.push(p(pll{next_cost + dist,next_node},node)); } } return shortest; } int main(){ cin >> n >> m; map<P,ll> dist; rep(i,m){ int u,v,c,d; cin >> u >> v >> c >> d; --u;--v; graph[u][v] = c; graph[v][u] = c; if(u>v) swap(u,v); dist[P(u,v)] = d; } //rep(i,n){ //for(auto p:graph[i]) //} vector<ll> res = Dijkstra(0); //rep(i,n) cout << res[i] << " "; //cout << endl; int now = n-1; while(now > 0){ int a = now; int b = before[now]; graph[a][b] = dist[P(min(a,b),max(a,b))]; graph[b][a] = graph[a][b]; now = b; //cout << now << endl; } vector<ll> ret = Dijkstra(n-1); cout << res[n-1] + ret[0] << endl; return 0; }