結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-23 10:03:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,516 bytes |
| コンパイル時間 | 1,839 ms |
| コンパイル使用メモリ | 176,212 KB |
| 実行使用メモリ | 42,304 KB |
| 最終ジャッジ日時 | 2024-09-22 00:29:50 |
| 合計ジャッジ時間 | 9,299 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 21 |
ソースコード
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
typedef pair<ll, ll> P;
struct edge {
ll to;
ll cost;
};
vector<edge> G[200010];
int main() {
ll n,m;
std::cin >> n>>m;
ll d[200010];
ll inf = 100000000000000+10;
Fill(d,inf);
d[0] = 0;
for (int i = 0; i < m; i++) {
ll tmp_a,tmp_b,tmp_c;
std::cin >> tmp_a>>tmp_b>>tmp_c;
tmp_a--;
tmp_b--;
edge e1 = {tmp_b,tmp_c};
edge e2 = {tmp_a,tmp_c};
G[tmp_a].push_back(e1);
G[tmp_b].push_back(e2);
G[tmp_a].push_back({tmp_b+n,0});
G[tmp_b].push_back({tmp_b+n,0});
G[tmp_b+n].push_back({tmp_a+n,tmp_c});
G[tmp_a+n].push_back({tmp_b+n,tmp_c});
}
priority_queue<P, vector<P>, greater<P> > que;
que.push(P(0, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first) continue;
for (int i=0; i<G[v].size(); ++i) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
for (int i = 0; i < n; i++) {
if(i==0){
std::cout << 0 << std::endl;
}else{
std::cout << d[i]+d[n+i]<< std::endl;
}
}
}