結果

問題 No.3653 Space-Time Courier
コンテスト
ユーザー Rino-program
提出日時 2026-07-21 23:09:27
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,157 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,372 ms
コンパイル使用メモリ 198,996 KB
実行使用メモリ 7,352 KB
最終ジャッジ日時 2026-08-28 21:02:50
合計ジャッジ時間 7,636 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 1 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const long long INF = 1e18;

struct Edge {
    int to;
    long long cost;
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, M;
    if (!(cin >> N >> M)) return 0;

    vector<long long> P(N + 1);
    for (int i = 1; i <= N; ++i) cin >> P[i];

    vector<vector<Edge>> adj(N + 1);
    for (int i = 0; i < M; ++i) {
        int u, v;
        long long t;
        cin >> u >> v >> t;
        adj[u].push_back({v, t});
    }

    long long min_total_cost = INF;
    long long min_count = 0;

    for (int start = 1; start <= N; ++start) {
        vector<long long> dist(N + 1, INF);
        vector<int> pop_count(N + 1, 0); // キューから取り出した回数
        
        // {distance, node}
        priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;

        dist[start] = 0;
        pq.push({0, start});

        while (!pq.empty()) {
            auto [d, u] = pq.top();
            pq.pop();

            // 古い情報ならスキップ
            if (d > dist[u]) continue;

            pop_count[u]++;
            // 嘘の要:1つの頂点を展開するのは最大100回まで(TLE回避)
            if (pop_count[u] > 100) continue;

            for (auto& edge : adj[u]) {
                int v = edge.to;
                long long weight = edge.cost;
                if (dist[u] + weight < dist[v]) {
                    dist[v] = dist[u] + weight;
                    pq.push({dist[v], v});
                }
            }
        }

        for (int v = 1; v <= N; ++v) {
            if (start == v || dist[v] == INF) continue;
            long long current_cost = dist[v] + P[start] + P[v];
            if (current_cost < min_total_cost) {
                min_total_cost = current_cost;
                min_count = 1;
            } else if (current_cost == min_total_cost) {
                min_count++;
            }
        }
    }

    if (min_total_cost == INF) cout << -1 << "\n";
    else cout << min_total_cost << " " << min_count << "\n";

    return 0;
}
0