結果

問題 No.807 umg tours
ユーザー onakaT_TitaionakaT_Titai
提出日時 2019-03-22 23:09:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 604 ms / 4,000 ms
コード長 2,460 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 98,408 KB
実行使用メモリ 42,052 KB
最終ジャッジ日時 2024-05-02 23:31:59
合計ジャッジ時間 8,435 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 334 ms
32,304 KB
testcase_12 AC 340 ms
24,428 KB
testcase_13 AC 452 ms
33,300 KB
testcase_14 AC 185 ms
16,128 KB
testcase_15 AC 142 ms
13,564 KB
testcase_16 AC 478 ms
35,076 KB
testcase_17 AC 601 ms
40,776 KB
testcase_18 AC 604 ms
40,932 KB
testcase_19 AC 596 ms
39,252 KB
testcase_20 AC 352 ms
22,656 KB
testcase_21 AC 361 ms
23,296 KB
testcase_22 AC 146 ms
11,904 KB
testcase_23 AC 109 ms
9,984 KB
testcase_24 AC 326 ms
32,684 KB
testcase_25 AC 597 ms
42,052 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