結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
noisy_noimin
|
| 提出日時 | 2019-03-22 23:11:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,408 bytes |
| コンパイル時間 | 1,201 ms |
| コンパイル使用メモリ | 116,200 KB |
| 実行使用メモリ | 31,140 KB |
| 最終ジャッジ日時 | 2024-09-19 06:34:52 |
| 合計ジャッジ時間 | 13,258 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 12 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int MAX_N = 112345;
const int dyx[4][2] = {
{ 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
map<ll, ll> d[2];
vector< vector<Pll> > edges(MAX_N);
struct State {
ll d, longest_edge;
int node;
State(int node, ll d, ll longest_edge): node(node), d(d), longest_edge(longest_edge) {}
bool operator>(const State& s) const{
return d > s.d;
}
};
void dijkstra(ll start, int shortcut){
priority_queue<State, vector<State>, greater<State> > que;
d[shortcut][start] = 0;
que.push(State(start, 0, 0));
while(!que.empty()){
State v = que.top(); que.pop();
if(d[shortcut].find(v.node) != d[shortcut].end() && d[shortcut][v.node] < v.d) continue;
for(Pll e: edges[v.node]){
if(shortcut) {
if(d[1].find(e.first) == d[1].end() || d[1][e.first] > d[1][v.node] + v.longest_edge + e.second - max(v.longest_edge, e.second)){
d[1][e.first] = d[1][v.node] + v.longest_edge + e.second - max(v.longest_edge, e.second);
que.push(State(e.first, d[1][e.first], max(v.longest_edge, e.second)));
}
} else {
if(d[0].find(e.first) == d[0].end() || d[0][e.first] > d[0][v.node] + e.second){
d[0][e.first] = d[0][v.node] + e.second;
que.push(State(e.first, d[0][e.first], 0));
}
}
}
}
}
int main() {
int n,m,a,b; ll c;
cin >> n >> m;
for(int i=0;i<m;++i) {
cin >> a >> b >> c;
edges[a].emplace_back(b, c);
edges[b].emplace_back(a, c);
}
dijkstra(1LL, 0);
dijkstra(1LL, 1);
for(int i=1;i<=n;++i) {
cout << d[0][i] + d[1][i] << endl;
// cerr << i << ": " << d[0][i] << " " << d[1][i] << " " << longest_edge[i] << endl;
}
}
noisy_noimin