結果

問題 No.807 umg tours
ユーザー kappybarkappybar
提出日時 2020-04-20 22:25:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,081 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 184,116 KB
実行使用メモリ 29,312 KB
最終ジャッジ日時 2024-04-16 01:02:13
合計ジャッジ時間 9,677 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,760 KB
testcase_01 WA -
testcase_02 AC 5 ms
5,760 KB
testcase_03 AC 5 ms
5,632 KB
testcase_04 WA -
testcase_05 AC 5 ms
5,632 KB
testcase_06 AC 5 ms
5,632 KB
testcase_07 AC 4 ms
5,760 KB
testcase_08 AC 4 ms
5,888 KB
testcase_09 AC 4 ms
5,632 KB
testcase_10 AC 4 ms
5,760 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 224 ms
13,256 KB
testcase_21 AC 235 ms
13,352 KB
testcase_22 AC 99 ms
9,036 KB
testcase_23 AC 74 ms
8,064 KB
testcase_24 AC 226 ms
24,320 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
using tp = tuple<ll,ll,ll>;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 100005,m = 200005;
vector<vector<P>> graph(n,vector<P>());

vector<ll> dijkstra(ll start){
    vector<ll> shortest(n);
    vector<bool> visited(n,false);
    priority_queue<pair<ll,ll>,vector<pair<ll ,ll>>,greater<pair<ll,ll>>> pq;
    pq.push(make_pair(0,start));
    while (!pq.empty()){
        pair<ll,ll> now = pq.top();
        pq.pop();
        ll cost,node;
        tie(cost,node) = now;
        if(visited[node]){
            continue;
        }else{
            shortest[node] = cost;
            visited[node] = true;
            for(pair<ll,ll> next:graph[node]){
                ll next_cost,next_node;
                tie(next_cost,next_node) = next;
                pq.push(make_pair(cost+next_cost,next_node));
            }
        }
    }
    return shortest;
}

vector<ll> dijkstra2(int start){
    vector<ll> res(n,0);
    vector<bool> seen(n,false);
    priority_queue<tp,vector<tp>,greater<tp>> pq;
    pq.push(tp(0,0,0));
    while(!pq.empty()){
        ll d = get<0>(pq.top()) + get<1>(pq.top());
        ll mx = get<1>(pq.top());
        ll node = get<2>(pq.top());
        pq.pop();
        if(seen[node]) continue;
        else{
            res[node] = d - mx;
            seen[node] = true;
            for(P next:graph[node]){
                ll next_cost,next_node ;
                tie(next_cost,next_node) = next;
                ll d_ = d + next_cost;
                ll mx_ = max(mx,next_cost);
                pq.push(tp(d_-mx_,mx_,next_node));
            }
        }
    }
    return res;
}

int main(){
    cin >> n >> m;
    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        --a;--b;
        graph[a].push_back(P(c,b));
        graph[b].push_back(P(c,a));
    }
    vector<ll> dis1 = dijkstra(0);
    vector<ll> dis2 = dijkstra2(0);
    rep(i,n){
        cout << dis1[i] + dis2[i] << '\n';
    }
    return 0;
}
0