結果

問題 No.807 umg tours
ユーザー hiro71687khiro71687k
提出日時 2023-03-02 07:04:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 4,000 ms
コード長 1,901 bytes
コンパイル時間 4,431 ms
コンパイル使用メモリ 268,824 KB
実行使用メモリ 20,808 KB
最終ジャッジ日時 2023-10-17 05:35:57
合計ジャッジ時間 9,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 208 ms
14,036 KB
testcase_12 AC 198 ms
12,528 KB
testcase_13 AC 268 ms
16,064 KB
testcase_14 AC 117 ms
9,408 KB
testcase_15 AC 94 ms
8,076 KB
testcase_16 AC 281 ms
16,768 KB
testcase_17 AC 339 ms
18,824 KB
testcase_18 AC 347 ms
18,872 KB
testcase_19 AC 347 ms
19,028 KB
testcase_20 AC 213 ms
12,952 KB
testcase_21 AC 225 ms
13,316 KB
testcase_22 AC 94 ms
7,812 KB
testcase_23 AC 73 ms
6,756 KB
testcase_24 AC 229 ms
15,976 KB
testcase_25 AC 351 ms
20,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll inf=10000000000000001;
ll mod=1000000007;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<vector<pair<ll,ll>>>g(n);
    for (ll i = 0; i < m; i++)
    {
        ll a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    vector<ll>memo(n,inf),memo2(n,inf);
    memo[0]=0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>que;
    que.push({0,0});
    vector<ll>ch(n,0);
    while (!que.empty())
    {
        ll v=que.top().second;
        que.pop();
        ch[v]=0;
        for (ll i = 0; i < g[v].size(); i++)
        {
            if (memo[g[v][i].first]>memo[v]+g[v][i].second)
            {
                memo[g[v][i].first]=memo[v]+g[v][i].second;
                if (ch[g[v][i].first]==0)
                {
                    que.push({memo[g[v][i].first],g[v][i].first});
                    ch[g[v][i].first]=1;
                }
            }
            if (memo2[g[v][i].first]>memo[v])
            {
                memo2[g[v][i].first]=memo[v];
                if (ch[g[v][i].first]==0)
                {
                    que.push({memo2[g[v][i].first],g[v][i].first});
                    ch[g[v][i].first]=1;
                }
            }
            if (memo2[g[v][i].first]>memo2[v]+g[v][i].second)
            {
                memo2[g[v][i].first]=memo2[v]+g[v][i].second;
                if (ch[g[v][i].first]==0)
                {
                    que.push({memo2[g[v][i].first],g[v][i].first});
                    ch[g[v][i].first]=1;
                }
            }
        }
    }
    ll ans=inf;
    cout << 0 << endl;
    for (ll i = 1; i < n; i++)
    {
        cout << memo[i]+memo2[i] << endl;
    }
}
0