結果

問題 No.807 umg tours
ユーザー hiro71687khiro71687k
提出日時 2023-03-02 07:03:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,894 bytes
コンパイル時間 5,075 ms
コンパイル使用メモリ 267,840 KB
実行使用メモリ 20,804 KB
最終ジャッジ日時 2023-10-17 05:35:14
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 255 ms
14,032 KB
testcase_12 AC 240 ms
12,524 KB
testcase_13 AC 334 ms
16,060 KB
testcase_14 AC 139 ms
9,404 KB
testcase_15 AC 112 ms
8,072 KB
testcase_16 AC 346 ms
16,764 KB
testcase_17 AC 422 ms
18,820 KB
testcase_18 AC 425 ms
18,868 KB
testcase_19 AC 432 ms
19,024 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 269 ms
15,972 KB
testcase_25 AC 422 ms
20,804 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=1000000001;
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