結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
Tlapesium
|
| 提出日時 | 2019-03-22 23:04:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,394 bytes |
| コンパイル時間 | 1,905 ms |
| コンパイル使用メモリ | 207,180 KB |
| 最終ジャッジ日時 | 2025-01-07 00:03:28 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 4 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
struct edge {
ll to;
ll cost;
};
// d v f
typedef pair<ll, pair<ll, bool>> P;
int main() {
int N, M;
cin >> N >> M;
vector<vector<edge>> G(N, vector<edge>());
for (int i = 0; i < M; i++) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
G[a].push_back({ b,c });
G[b].push_back({ a,c });
}
vector<ll> d1(N, INF), d2(N, INF), d3(N, INF);
priority_queue<P, vector<P>, greater<P>> q, q_;
d1[0] = 0; d2[0] = 0, d3[0] = 0;
q.push(P{ 0,{0,false} });
while (!q.empty()) {
P p = q.top(); q.pop();
ll v = p.second.first;
for (int i = 0; i < G[v].size(); i++) {
edge e = G[v][i];
if (d1[e.to] > d1[v] + e.cost) {
d1[e.to] = d1[v] + e.cost;
q.push(P{ d1[e.to],{ e.to, p.second.second } });
}
if (d3[e.to] > p.first) {
d3[e.to] = p.first;
q_.push(P{ d3[e.to],{ e.to, true } });
}
}
}
while (!q_.empty()) {
P p = q_.top(); q_.pop();
ll v = p.second.first;
if (d3[v] < p.first)continue;
for (int i = 0; i < G[v].size(); i++) {
edge e = G[v][i];
if (d3[e.to] > d3[v] + e.cost) {
d3[e.to] = d3[v] + e.cost;
q_.push(P{ d3[e.to],{ e.to, p.second.second } });
}
}
}
for (int i = 0; i < N; i++) {
cout << d3[i] + d1[i] << endl;
}
}
Tlapesium