結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2019-03-22 23:37:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,083 bytes |
| コンパイル時間 | 1,826 ms |
| コンパイル使用メモリ | 181,948 KB |
| 実行使用メモリ | 20,160 KB |
| 最終ジャッジ日時 | 2024-09-19 07:04:56 |
| 合計ジャッジ時間 | 7,710 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 TLE * 1 -- * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
int64_t n, m;
cin >> n >> m;
vector<vector<pair<int64_t, int>>> g(n);
for (int i = 0; i < m; i++)
{
int64_t a, b, c;
cin >> a >> b >> c;
a--;
b--;
g[a].push_back({c, b});
g[b].push_back({c, a});
}
vector<vector<int64_t>> dist(n, vector<int64_t>(2, (1LL << 60)));
dist[0][0] = 0;
priority_queue<pair<int64_t, pair<int, int>>> pq;
pq.push({dist[0][0], {0, 0}});
while (!pq.empty())
{
int64_t score = pq.top().first;
int x = pq.top().second.first;
int y = pq.top().second.second;
pq.pop();
if (dist[x][y] < score)
{
continue;
}
for (auto &p : g[x])
{
int64_t cost = p.first;
int to = p.second;
if (dist[x][y] + cost < dist[to][y])
{
dist[to][y] = dist[x][y] + cost;
pq.push({dist[to][y], {to, y}});
}
if (y == 0)
{
if (dist[x][y] < dist[to][1])
{
dist[to][1] = dist[x][y];
pq.push({dist[to][1], {to, 1}});
}
}
}
}
cout << 0 << endl;
for (int i = 1; i < n; i++)
{
cout << dist[i][0] + dist[i][1] << endl;
}
return 0;
}
ldsyb