結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-22 22:26:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,239 bytes |
| コンパイル時間 | 2,504 ms |
| コンパイル使用メモリ | 170,224 KB |
| 実行使用メモリ | 39,784 KB |
| 最終ジャッジ日時 | 2024-11-23 19:05:24 |
| 合計ジャッジ時間 | 14,069 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 TLE * 1 |
ソースコード
#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);
}