結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
onakaT_Titai
|
| 提出日時 | 2019-03-22 23:05:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,401 bytes |
| コンパイル時間 | 984 ms |
| コンパイル使用メモリ | 108,232 KB |
| 実行使用メモリ | 41,948 KB |
| 最終ジャッジ日時 | 2024-09-19 06:30:19 |
| 合計ジャッジ時間 | 7,363 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 21 |
ソースコード
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
//using namespace boost::multiprecision;
const Int MOD = 1000000007;
Int mod_pow(Int x, Int n) {
Int res = 1;
while(n > 0) {
if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
x = (x * x) % MOD;
n >>= 1; //右シフト(n = n >> 1)
}
return res;
}
//最大公約数
template<typename T>
T gcd(T a, T b) {
return b != 0 ? gcd(b, a % b) : a;
}
//最小公倍数
template<typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
struct Edge{
int from, to;
Int cost;
};
template <typename T>
vector<T> dijkstra(vector<vector<Edge>> &G, int s) {
int V = G.size();
vector<T> d(V); fill(d.begin(), d.end(), numeric_limits<T>::max());
priority_queue<pair<T, int> , vector< pair<T, int> >, greater< pair<T, int> > > que;
d[s] = 0;
que.push(make_pair(0,s));
while(!que.empty()) {
pair<T, int> p = que.top(); que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i=0; i<G[v].size(); i++) {
Edge e = G[v][i];
if(d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(make_pair(d[e.to], e.to));
}
}
}
return d;
}
int main(){
cin.tie(0);
int N, M; cin >> N >> M;
vector<vector<Edge>> G(N*2+1);
for (int i = 0; i < M; i++){
int a, b;
Int c; cin >> a >> b >> c;
Edge e = {a, b, c};
Edge e2 = {b, a, c};
Edge e3 = {a+N, b+N, c};
Edge e4 = {b+N, a+N, c};
Edge e5 = {a, b+N, 0};
G[a].push_back(e);
G[b].push_back(e2);
G[a+N].push_back(e3);
G[b+N].push_back(e4);
G[a].push_back(e5);
}
vector<Int> d = dijkstra<Int>(G, 1);
for (int i = 1; i <= N; i++){
if (i == 1) cout << 0 << endl;
else cout << d[i] + d[i+N] << endl;
}
return 0;
}
onakaT_Titai