結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
veqcc
|
| 提出日時 | 2019-03-22 22:08:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,004 bytes |
| コンパイル時間 | 949 ms |
| コンパイル使用メモリ | 112,608 KB |
| 実行使用メモリ | 16,452 KB |
| 最終ジャッジ日時 | 2024-09-19 05:32:16 |
| 合計ジャッジ時間 | 3,387 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 18 |
ソースコード
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 18;
struct edge {
int to;
ll cost;
};
typedef pair <int, int> P;
typedef pair <ll, P> PP;
int V, E;
vector <edge> G[100005];
int d[2][100005];
// 0: チケットを使わない最短距離
// 1: チケットを1回使った時の最短距離
void dijkstra(int s) {
priority_queue<PP, vector<PP>, greater<PP>> q;
fill(d[0], d[1]+V, INF);
d[0][s] = d[1][s] = 0;
q.push(PP(0LL, P(s, 0)));
while (!q.empty()) {
PP p = q.top();
q.pop();
int cost = p.first;
int cur = p.second.first;
int used = p.second.second;
if (d[used][cur] < cost) continue;
for (edge e : G[cur]) {
if (used == 1) {
if (d[1][e.to] > d[1][cur] + e.cost) {
d[1][e.to] = d[1][cur] + e.cost;
q.push(PP(d[1][e.to], P(e.to, 1)));
}
} else {
if (d[0][e.to] > d[0][cur] + e.cost) {
d[0][e.to] = d[0][cur] + e.cost;
q.push(PP(d[0][e.to], P(e.to, 0)));
}
if (d[1][e.to] > d[0][cur]) {
d[1][e.to] = d[0][cur];
q.push(PP(d[1][e.to], P(e.to, 1)));
}
}
}
}
}
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> V >> E;
for (int i = 0; i < E; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
a--; b--;
G[a].push_back((edge){b, c});
G[b].push_back((edge){a, c});
}
dijkstra(0);
for (int i = 0; i < V; i++) {
cout << d[0][i] + d[1][i] << "\n";
}
return 0;
}
veqcc