結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-22 23:06:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,716 bytes |
| コンパイル時間 | 1,837 ms |
| コンパイル使用メモリ | 179,720 KB |
| 実行使用メモリ | 26,368 KB |
| 最終ジャッジ日時 | 2024-09-19 06:30:35 |
| 合計ジャッジ時間 | 6,642 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct State {
int at;
ll cost;
ll maxc;
int prev;
State(int at, ll cost, int prev) : at(at), cost(cost), maxc(0), prev(prev) {}
State(int at, ll cost, ll maxc, int prev) : at(at), cost(cost), maxc(maxc), prev(prev) {}
bool operator>(const State& s) const {
if (cost != s.cost) return cost > s.cost;
return maxc > s.maxc;
}
};
struct Edge {
int to;
ll cost;
Edge(int to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList; //隣接リスト
const ll INF = 1e18;
const int NONE = -1;
AdjList graph;
//sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点
void dijkstra(int s, vector<ll>& minc, vector<int>& Prev){
priority_queue<State, vector<State>, greater<State> > pq;
pq.push(State(s, 0, NONE));
while(!pq.empty()) {
State cur = pq.top();
pq.pop();
if (minc[cur.at] <= cur.cost) continue;
minc[cur.at] = cur.cost;
Prev[cur.at] = cur.prev;
for(Edge e : graph[cur.at]) {
ll cost = cur.cost + e.cost;
if (minc[e.to] <= cost) continue;
pq.push(State(e.to, cost, cur.at));
}
}
}
void dijkstra2(int s, vector<ll>& minc, vector<int>& Prev){
priority_queue<State, vector<State>, greater<State> > pq;
vector<ll> mxc(minc.size(), 0);
pq.push(State(s, 0, 0, NONE));
while(!pq.empty()) {
State cur = pq.top();
pq.pop();
if (minc[cur.at] < cur.cost || (minc[cur.at] == cur.cost && mxc[cur.at] <= cur.maxc)) continue;
minc[cur.at] = cur.cost;
Prev[cur.at] = cur.prev;
mxc[cur.at] = cur.maxc;
for(Edge e : graph[cur.at]) {
ll maxc = max(e.cost, cur.maxc);
ll cost = cur.cost;
if (cur.maxc < maxc) {
cost += cur.maxc;
} else {
cost += e.cost;
}
if (minc[e.to] < cost || (minc[e.to] == cost && mxc[e.to] <= maxc)) continue;
pq.push(State(e.to, cost, maxc, cur.at));
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
graph.resize(n);
for (int i = 0; i < m; i++) {
int a, b;
ll c;
cin >> a >> b >> c;
a--; b--;
graph[a].emplace_back(b, c);
graph[b].emplace_back(a, c);
}
vector<ll> minc(n, INF), minc2(n, INF);
vector<int> p1(n, NONE), p2(n, NONE);
dijkstra(0, minc, p1);
dijkstra2(0, minc2, p2);
for (int i = 0; i < n; i++) {
cout << minc[i] + minc2[i] << endl;
}
return 0;
}