結果

問題 No.3653 Space-Time Courier
コンテスト
ユーザー とある理系大学生の日常
提出日時 2026-08-05 02:50:10
言語 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
結果
TLE  
実行時間 -
コード長 1,956 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,151 ms
コンパイル使用メモリ 178,248 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2026-08-28 21:14:40
合計ジャッジ時間 31,590 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 TLE * 6 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;

using int64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    vector<int64> P(N);
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
    }

    // 加算時のオーバーフローを避けるため、
    // long long の最大値より十分小さい値を使う。
    const int64 INF = numeric_limits<int64>::max() / 4;

    vector<vector<int64>> dist(N, vector<int64>(N, INF));

    for (int i = 0; i < N; ++i) {
        dist[i][i] = 0;
    }

    for (int i = 0; i < M; ++i) {
        int u, v;
        int64 t;
        cin >> u >> v >> t;

        --u;
        --v;

        // 同じ頂点間に複数のゲートがある場合に対応
        dist[u][v] = min(dist[u][v], t);
    }

    // ワーシャル・フロイド法
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            if (dist[i][k] == INF) {
                continue;
            }

            for (int j = 0; j < N; ++j) {
                if (dist[k][j] == INF) {
                    continue;
                }

                dist[i][j] = min(
                    dist[i][j],
                    dist[i][k] + dist[k][j]
                );
            }
        }
    }

    int64 minimumCost = INF;
    int64 countPairs = 0;

    // (A, B) は順序付きペアとして数える
    for (int A = 0; A < N; ++A) {
        for (int B = 0; B < N; ++B) {
            if (A == B || dist[A][B] == INF) {
                continue;
            }

            int64 cost = dist[A][B] + P[A] + P[B];

            if (cost < minimumCost) {
                minimumCost = cost;
                countPairs = 1;
            } else if (cost == minimumCost) {
                ++countPairs;
            }
        }
    }

    cout << minimumCost << ' ' << countPairs << '\n';

    return 0;
}
0