結果
問題 | No.807 umg tours |
ユーザー | yuji9511 |
提出日時 | 2019-03-22 22:26:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,239 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 171,744 KB |
実行使用メモリ | 39,360 KB |
最終ジャッジ日時 | 2024-05-02 23:28:13 |
合計ジャッジ時間 | 11,591 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
11,264 KB |
testcase_01 | AC | 7 ms
11,264 KB |
testcase_02 | AC | 8 ms
11,264 KB |
testcase_03 | AC | 7 ms
11,264 KB |
testcase_04 | AC | 7 ms
11,264 KB |
testcase_05 | AC | 7 ms
11,264 KB |
testcase_06 | AC | 6 ms
11,264 KB |
testcase_07 | AC | 6 ms
11,264 KB |
testcase_08 | AC | 7 ms
11,136 KB |
testcase_09 | AC | 6 ms
11,264 KB |
testcase_10 | AC | 6 ms
11,136 KB |
testcase_11 | AC | 184 ms
22,812 KB |
testcase_12 | AC | 251 ms
22,568 KB |
testcase_13 | AC | 317 ms
25,520 KB |
testcase_14 | AC | 135 ms
20,560 KB |
testcase_15 | AC | 107 ms
16,876 KB |
testcase_16 | AC | 332 ms
26,440 KB |
testcase_17 | AC | 442 ms
33,416 KB |
testcase_18 | AC | 450 ms
33,452 KB |
testcase_19 | AC | 436 ms
33,368 KB |
testcase_20 | AC | 276 ms
22,104 KB |
testcase_21 | AC | 291 ms
22,300 KB |
testcase_22 | AC | 114 ms
16,268 KB |
testcase_23 | AC | 89 ms
15,780 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); }