結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
TAISA_
|
| 提出日時 | 2019-03-22 21:36:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,390 bytes |
| コンパイル時間 | 2,094 ms |
| コンパイル使用メモリ | 183,588 KB |
| 実行使用メモリ | 36,700 KB |
| 最終ジャッジ日時 | 2024-11-23 18:52:30 |
| 合計ジャッジ時間 | 13,033 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;
struct edge {
int to;
ll cost;
};
int main() {
int n, m;
cin >> n >> m;
vector<vector<edge>> G(n);
for(int i = 0; i < m; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
--a;
--b;
G[a].push_back({b, c});
G[b].push_back({a, c});
}
priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> q;
vector<vector<ll>> d(n, vector<ll>(2, LINF));
d[0][0] = 0;
d[0][1] = 0;
q.push(mp(P(0, 0), 0));
q.push(mp(P(0, 0), 1));
while(!q.empty()) {
auto p = q.top();
q.pop();
int v = p.first.second, f = p.second;
for(auto e : G[v]) {
if(d[e.to][f] > d[v][f] + e.cost) {
d[e.to][f] = d[v][f] + e.cost;
q.push(mp(P(d[e.to][f], e.to), f));
}
if(f == 0) {
if(d[e.to][1] > d[v][0]) {
d[e.to][1] = d[v][0];
q.push(mp(P(d[e.to][1], e.to), 1));
}
}
}
}
for(int i = 0; i < n; i++) {
cout << d[i][0] + d[i][1] << endl;
}
}
TAISA_