結果

問題 No.807 umg tours
ユーザー tottoripapertottoripaper
提出日時 2019-03-22 22:14:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 334 ms / 4,000 ms
コード長 1,622 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 184,896 KB
実行使用メモリ 24,488 KB
最終ジャッジ日時 2024-05-02 23:26:22
合計ジャッジ時間 6,477 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,168 KB
testcase_01 AC 4 ms
7,296 KB
testcase_02 AC 4 ms
7,296 KB
testcase_03 AC 3 ms
7,296 KB
testcase_04 AC 3 ms
7,256 KB
testcase_05 AC 3 ms
7,296 KB
testcase_06 AC 3 ms
7,296 KB
testcase_07 AC 3 ms
7,296 KB
testcase_08 AC 3 ms
7,236 KB
testcase_09 AC 4 ms
7,236 KB
testcase_10 AC 2 ms
7,368 KB
testcase_11 AC 145 ms
18,912 KB
testcase_12 AC 185 ms
15,848 KB
testcase_13 AC 233 ms
18,544 KB
testcase_14 AC 105 ms
12,136 KB
testcase_15 AC 81 ms
10,692 KB
testcase_16 AC 232 ms
19,464 KB
testcase_17 AC 313 ms
23,372 KB
testcase_18 AC 319 ms
23,408 KB
testcase_19 AC 298 ms
20,244 KB
testcase_20 AC 216 ms
12,740 KB
testcase_21 AC 203 ms
13,056 KB
testcase_22 AC 86 ms
9,728 KB
testcase_23 AC 71 ms
9,284 KB
testcase_24 AC 197 ms
21,152 KB
testcase_25 AC 334 ms
24,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<ll,ll>;
using T = std::tuple<ll,ll,ll>;

constexpr ll INF = std::numeric_limits<ll>::max() / 2;
int N, M;
std::vector<P> G[100100];
std::priority_queue<T, std::vector<T>, std::greater<T>> pq;
ll dist[100100][2];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int a, b, c;
        std::cin >> a >> b >> c;

        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    std::fill(&dist[0][0], &dist[0][0] + 100100 * 2, INF);

    dist[1][0] = 0;
    dist[1][1] = 0;
    pq.emplace(0, 1, 0);

    until(pq.empty()){
        int v, t;
        ll d;
        std::tie(d, v, t) = pq.top();
        pq.pop();

        if(d > dist[v][t]){
            continue;
        }

        for(auto &e : G[v]){
            int w, c;
            std::tie(w, c) = e;

            if(d + c < dist[w][t]){
                dist[w][t] = d + c;
                pq.emplace(dist[w][t], w, t);
            }
        }

        if(t == 0){
            for(auto &e : G[v]){
                int w;
                std::tie(w, std::ignore) = e;

                if(d < dist[w][1]){
                    dist[w][1] = d;
                    pq.emplace(dist[w][1], w, 1);
                }
            }
        }
    }

    for(int i=1;i<=N;++i){
        ll mn = dist[i][0] + dist[i][1];
        std::cout << mn << std::endl;
    }
}
0