結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
gazelle
|
| 提出日時 | 2019-03-22 21:34:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 366 ms / 4,000 ms |
| コード長 | 1,655 bytes |
| コンパイル時間 | 1,058 ms |
| コンパイル使用メモリ | 127,564 KB |
| 最終ジャッジ日時 | 2025-01-06 23:45:39 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<vector<pll>> g(n);
REP(i, m) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a].pb({b, c});
g[b].pb({a, c});
}
vector<vector<ll>> dir(n, vector<ll>(2, INF * INF));
dir[0][0] = 0;
priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> q;
q.push({0, {0, 0}});
while(!q.empty()) {
ll c = q.top().first;
ll p = q.top().second.first, d = q.top().second.second;
q.pop();
if(dir[p][d] != c) continue;
REP(i, g[p].size()) {
ll np = g[p][i].first, cost = g[p][i].second;
if(dir[np][d] > c + cost) {
dir[np][d] = c + cost;
q.push({dir[np][d], {np, d}});
}
if(d == 0 && dir[np][1] > c) {
dir[np][1] = c;
q.push({dir[np][1], {np, 1}});
}
}
}
REP(i, n) {
if(i == 0) {
cout << 0 << endl;
} else {
cout << dir[i][0] + dir[i][1] << endl;
}
}
return 0;
}
/* --------------------------------------- */
gazelle