結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
chocobo
|
| 提出日時 | 2019-03-22 21:53:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 608 ms / 4,000 ms |
| コード長 | 1,578 bytes |
| コンパイル時間 | 1,294 ms |
| コンパイル使用メモリ | 111,880 KB |
| 実行使用メモリ | 27,860 KB |
| 最終ジャッジ日時 | 2024-11-23 18:57:55 |
| 合計ジャッジ時間 | 8,508 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for(int i = 0; i < n; i++)
using P = pair<ll, ll>;
using T = pair<ll, pair<ll, ll>>;
int main() {
ll n, m;
cin >> n >> m;
vector<vector<P>> g(n);
REP(i, m) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a].push_back({ b, c });
g[b].push_back({ a, c });
}
vector<vector<ll>> dist(n, vector<ll>(2, INF));
dist[0][0] = dist[0][1] = 0;
priority_queue<T, vector<T>, greater<T>> que;
que.push({ 0, {0, 0} });
while (!que.empty()) {
auto tmp = que.top(); que.pop();
ll now = tmp.second.first, d = tmp.first, f = tmp.second.second;
if (dist[now][f] < d) continue;
for (auto &e : g[now]) {
ll v = e.first, c = e.second;
if (f == 0) {
if (dist[v][0] > d + c) {
dist[v][0] = d + c;
que.push({ d + c, {v, 0} });
}
if (dist[v][1] > d) {
dist[v][1] = d;
que.push({ d, {v, 1} });
}
}
else {
if (dist[v][1] > d + c) {
dist[v][1] = d + c;
que.push({ d + c, {v, 1} });
}
}
}
}
/*
REP(i, n) {
cout << dist[i][0] << " " << dist[i][1] << endl;
}
*/
REP(i, n) {
cout << dist[i][0] + dist[i][1] << endl;
}
}
chocobo