結果

問題 No.807 umg tours
ユーザー onakaT_TitaionakaT_Titai
提出日時 2019-03-22 23:09:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 591 ms / 4,000 ms
コード長 2,460 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 97,312 KB
実行使用メモリ 44,844 KB
最終ジャッジ日時 2023-08-15 12:06:25
合計ジャッジ時間 8,559 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 331 ms
32,092 KB
testcase_12 AC 334 ms
24,192 KB
testcase_13 AC 455 ms
33,048 KB
testcase_14 AC 185 ms
15,844 KB
testcase_15 AC 145 ms
13,496 KB
testcase_16 AC 466 ms
34,752 KB
testcase_17 AC 582 ms
41,264 KB
testcase_18 AC 590 ms
42,268 KB
testcase_19 AC 573 ms
39,184 KB
testcase_20 AC 342 ms
22,440 KB
testcase_21 AC 353 ms
23,144 KB
testcase_22 AC 143 ms
11,812 KB
testcase_23 AC 110 ms
9,920 KB
testcase_24 AC 313 ms
32,732 KB
testcase_25 AC 591 ms
44,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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};
        Edge e6 = {b, a+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);
        G[b].push_back(e6);
    }
    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;
}

0