結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
taki_g
|
| 提出日時 | 2019-04-01 11:05:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,438 ms / 4,000 ms |
| コード長 | 1,635 bytes |
| コンパイル時間 | 1,764 ms |
| コンパイル使用メモリ | 177,024 KB |
| 実行使用メモリ | 70,060 KB |
| 最終ジャッジ日時 | 2024-11-23 19:23:00 |
| 合計ジャッジ時間 | 12,010 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
typedef pair<ll, ll> P;
ll dp[200010];
vector<vector<P>> road(200010);
int main(){
ll N,M;
cin >> N >> M;
rep(i,M){
ll a,b,c;
cin >> a >> b >> c;
road[a].push_back(P(b,c));
road[a].push_back(P(b+N,0));
road[b].push_back(P(a,c));
road[b].push_back(P(a+N,0));
road[a+N].push_back(P(b+N,c));
road[b+N].push_back(P(a+N,c));
}
priority_queue<P,vector<P>,greater<P>> q;
q.push(P(1,0));
for(int i=2;i<=2*N;i++){
if(i!=N+1) dp[i] = (ll)1e18;
}
while(!q.empty()){
P p = q.top();q.pop();
ll num = p.first;
ll cost = p.second;
if(dp[num] < cost)continue;
for(auto next_p: road[num]){
ll next_num = next_p.first;
ll next_cost = next_p.second;
if(dp[next_num] > cost+next_cost){
dp[next_num] = cost+next_cost;
q.push(P(next_num,dp[next_num]));
}
}
}
REP(i,1,N+1){
cout << (dp[i]+dp[i+N]) << endl;
}
return 0;
}
taki_g