結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
momohara
|
| 提出日時 | 2020-02-08 23:11:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 485 ms / 4,000 ms |
| コード長 | 2,408 bytes |
| コンパイル時間 | 1,106 ms |
| コンパイル使用メモリ | 111,132 KB |
| 実行使用メモリ | 54,976 KB |
| 最終ジャッジ日時 | 2024-11-23 19:49:24 |
| 合計ジャッジ時間 | 7,215 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
using namespace std;
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define F first
#define S second
#define en "\n"
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グラフ関連
struct Edge {//グラフ
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to; cap = _cap; rev = _rev;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}
void Dijkstra(Graph& G, ll s, Array& d) {//O(|E|log|V|)
d.resize(G.size());
REP(i, d.size())d[i] = INF;
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, s));
while (!q.empty()) {
P a = q.top();
q.pop();
if (d[a.second] < a.first)continue;
REP(i, G[a.second].size()) {
Edge e = G[a.second][i];
if (d[e.to] > d[a.second] + e.cap) {
d[e.to] = d[a.second] + e.cap;
q.push(make_pair(d[e.to], e.to));
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, m;
cin >> n >> m;
Graph g(2*n);//チケット使用前、使用後
REP(i, m) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
add_edge(g, a, b, c, true, c);
add_edge(g, a + n, b + n, c, true, c);
add_edge(g, a, b + n, 0, false, 0);//チケットを使う
add_edge(g, b, a + n, 0, false, 0);//チケットを使う
}
Array d;
Dijkstra(g, 0, d);
cout << 0 << endl;
rep(i, 1, n) {
cout << d[i] + d[i + n] << endl;
}
return 0;
}
momohara