結果

問題 No.3653 Space-Time Courier
コンテスト
ユーザー GOTKAKO
提出日時 2026-08-28 22:08:57
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 651 ms / 4,000 ms
+ 883µs
コード長 1,450 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,364 ms
コンパイル使用メモリ 224,924 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-28 22:09:23
合計ジャッジ時間 8,513 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N,M; cin >> N >> M;
    vector<long long> P(N);
    for(auto &p : P) cin >> p;
    long long inf = 1e16;
    vector<vector<pair<int,long long>>> Graph(N);
    for(int i=0; i<M; i++){
        int u,v; cin >> u >> v;
        u--; v--;
        int w; cin >> w;
        Graph.at(u).push_back({v,w});
    }
    vector<long long> X(N);
    X.at(0) = 0;
    for(int t=0; t<=N; t++) for(int pos=0; pos<N; pos++) for(auto [to,w] : Graph.at(pos)){
        X.at(to) = min(X.at(to),X.at(pos)+w);
    }

    long long best = inf,answer = 0;
    for(int i=0; i<N; i++){
        vector<long long> dist(N,inf);
        dist.at(i) = 0;
        priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<>> Q;
        Q.push({0,i});
        while(Q.size()){
            auto [d,pos] = Q.top(); Q.pop();
            if(dist.at(pos) != d) continue;
            for(auto [to,w] : Graph.at(pos)){
                if(d+w+X.at(pos)-X.at(to) < dist.at(to)) dist.at(to) = d+w+X.at(pos)-X.at(to),Q.push({dist.at(to),to});
            }
        }
        for(int k=0; k<N; k++){
            if(i == k) continue;
            long long now = dist.at(k)+X.at(k)-X.at(i)+P.at(k)+P.at(i);
            if(now < best) best = now,answer = 1;
            else if(now == best) answer++;
        }
    }
    cout << best << " " << answer << endl;
}
0