結果

問題 No.807 umg tours
ユーザー Kiona1018Kiona1018
提出日時 2019-09-14 22:02:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,529 ms / 4,000 ms
コード長 1,420 bytes
コンパイル時間 2,680 ms
コンパイル使用メモリ 178,640 KB
実行使用メモリ 79,580 KB
最終ジャッジ日時 2023-08-15 12:31:41
合計ジャッジ時間 19,801 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,860 KB
testcase_01 AC 4 ms
5,800 KB
testcase_02 AC 5 ms
5,828 KB
testcase_03 AC 4 ms
5,904 KB
testcase_04 AC 3 ms
5,768 KB
testcase_05 AC 3 ms
5,976 KB
testcase_06 AC 4 ms
5,928 KB
testcase_07 AC 5 ms
5,904 KB
testcase_08 AC 3 ms
5,848 KB
testcase_09 AC 3 ms
5,804 KB
testcase_10 AC 3 ms
5,760 KB
testcase_11 AC 2,192 ms
76,316 KB
testcase_12 AC 868 ms
43,116 KB
testcase_13 AC 2,041 ms
78,572 KB
testcase_14 AC 521 ms
25,720 KB
testcase_15 AC 350 ms
17,504 KB
testcase_16 AC 963 ms
29,732 KB
testcase_17 AC 1,653 ms
79,580 KB
testcase_18 AC 2,529 ms
79,580 KB
testcase_19 AC 2,046 ms
79,160 KB
testcase_20 AC 354 ms
15,008 KB
testcase_21 AC 382 ms
15,300 KB
testcase_22 AC 159 ms
9,836 KB
testcase_23 AC 120 ms
9,180 KB
testcase_24 AC 367 ms
19,808 KB
testcase_25 AC 719 ms
29,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
const int MAX_N = 100000;
const ll INF = 1e18;

struct edge{int to, weight;};
vector<edge> from[MAX_N];

int main()
{
    int n, m;
    cin >> n >> m;

    rep(i, 0, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;

        edge e{b, c};
        from[a].push_back(edge{b, c});
        from[b].push_back(edge{a, c});        
    }

    vector<ll> dis(2*n, INF);
    priority_queue<pll, vector<pll>, greater<pll>> que;
    que.push(make_pair(0, 0));
    que.push(make_pair(n, 0));
    while (que.size() > 0)
    {
        ll node, distance;
        tie(node, distance) = que.top();
        que.pop();

        if (dis[node] < distance) continue;

        dis[node] = distance;
        if (n <= node)
            for (edge e: from[node % n])
                que.push(make_pair(n + e.to, (ll)distance + e.weight));
        else
        {
            for (edge e: from[node])
            {
                que.push(make_pair(e.to, (ll) distance + e.weight));
                que.push(make_pair(e.to + n, (ll) distance));
            }
        }
    }

    rep(i, 0, n)
        cout << (ll) dis[i] + dis[n + i] << endl;
        // cout << dis[i] << endl;
    return 0;
}
0