結果
問題 | No.807 umg tours |
ユーザー | yuji9511 |
提出日時 | 2019-03-22 22:26:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,239 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 156,572 KB |
実行使用メモリ | 37,384 KB |
最終ジャッジ日時 | 2023-08-15 12:02:40 |
合計ジャッジ時間 | 12,731 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
14,980 KB |
testcase_01 | AC | 4 ms
9,768 KB |
testcase_02 | AC | 4 ms
10,156 KB |
testcase_03 | AC | 4 ms
9,388 KB |
testcase_04 | AC | 4 ms
9,648 KB |
testcase_05 | AC | 5 ms
9,356 KB |
testcase_06 | AC | 5 ms
9,604 KB |
testcase_07 | AC | 4 ms
9,352 KB |
testcase_08 | AC | 4 ms
9,152 KB |
testcase_09 | AC | 3 ms
9,916 KB |
testcase_10 | AC | 4 ms
9,604 KB |
testcase_11 | AC | 216 ms
22,684 KB |
testcase_12 | AC | 280 ms
23,236 KB |
testcase_13 | AC | 369 ms
25,652 KB |
testcase_14 | AC | 158 ms
21,336 KB |
testcase_15 | AC | 120 ms
17,108 KB |
testcase_16 | AC | 374 ms
26,872 KB |
testcase_17 | AC | 485 ms
33,372 KB |
testcase_18 | AC | 489 ms
33,900 KB |
testcase_19 | AC | 479 ms
34,668 KB |
testcase_20 | AC | 299 ms
21,744 KB |
testcase_21 | AC | 337 ms
22,820 KB |
testcase_22 | AC | 128 ms
15,328 KB |
testcase_23 | AC | 97 ms
15,372 KB |
testcase_24 | TLE | - |
testcase_25 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> lpair; typedef pair<ll, lpair> lpair2; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,M; cin >> N >> M; ll A[100010], B[100010], C[100010]; vector<lpair> tree[100010]; rep(i,0,M){ cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--; tree[A[i]].push_back(make_pair(B[i], C[i])); tree[B[i]].push_back(make_pair(A[i], C[i])); } // ll dist1[100010] = {}, dist2[100010]; // rep(i,1,N){ // dist1[i] = INF; // dist2[i] = INF; // } ll dp[100010][2] = {}; rep(i,1,N){ dp[i][0] = INF; dp[i][1] = INF; } priority_queue<lpair2, vector<lpair2> ,greater<lpair2> > pq; rep(i,0,N) pq.push(make_pair(dp[i][0], make_pair(0,i))); rep(i,0,N) pq.push(make_pair(dp[i][1], make_pair(1,i))); ll is_visit[100010][2] = {}; // ll max_length[100010] = {}; while(!pq.empty()){ lpair2 l1 = pq.top(); ll len = l1.first; ll t1 = l1.second.first; ll pos = l1.second.second; pq.pop(); is_visit[pos][t1] = 1; for(auto &e: tree[pos]){ if(t1 == 0){ // if(dp[e.first][0] > dp[pos][0]){ // if(!is_visit[e.first][0]){ // dp[e.first][0] = dp[pos][0]; // pq.push(make_pair(dp[e.first][0], make_pair(e.first, 0))); // } // } if(dp[e.first][0] > dp[pos][0] + e.second){ if(!is_visit[e.first][0]){ dp[e.first][0] = dp[pos][0] + e.second; pq.push(make_pair(dp[e.first][0], make_pair(0,e.first))); } } if(dp[e.first][1] > dp[pos][0]){ if(!is_visit[e.first][1]){ dp[e.first][1] = dp[pos][0]; pq.push(make_pair(dp[e.first][1], make_pair(1,e.first))); } } }else{ if(dp[e.first][1] > dp[pos][1] + e.second){ if(!is_visit[e.first][1]){ dp[e.first][1] = dp[pos][1] + e.second; pq.push(make_pair(dp[e.first][1], make_pair(1,e.first))); } } } // if(dist[e.first] > dist[l1.second] + e.second){ // if(!is_visit[e.first]){ // dist[e.first] = dist[l1.second] + e.second; // max_length[e.first] = max(max_length[l1.second], e.second); // pq.push(make_pair(dist[e.first], e.first)); // } // } } } rep(i,0,N){ print(dp[i][0] + dp[i][1]); } // printa(max_length, N); }