結果

問題 No.3653 Space-Time Courier
コンテスト
ユーザー detteiuu
提出日時 2026-08-28 22:23:18
言語 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  
実行時間 -
コード長 3,386 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,505 ms
コンパイル使用メモリ 434,528 KB
実行使用メモリ 101,760 KB
最終ジャッジ日時 2026-08-28 22:24:58
合計ジャッジ時間 16,415 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define pass (void)0
#define INF (1<<30)-1
#define INFLL (1LL<<60)-1
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define YesNo(cond) cout << ((cond) ? "Yes\n" : "No\n")
#define YESNO(cond) cout << ((cond) ? "YES\n" : "NO\n")

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

template <typename T> void print(const T& value) { cout << value << "\n"; }
template <typename T> void print(const vector<T>& vec) { for (auto& v : vec) cout << v << " "; cout << "\n"; }
template <typename T> void input(vector<T>& vec) { for (auto& v : vec) cin >> v; };
template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using vm = vector<mint>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    ll N, M;
    cin >> N >> M;
    vl P(N);
    input(P);
    vector<vector<pll>> G(N, vector<pll> ());
    rep (_, M) {
        ll u, v, t;
        cin >> u >> v >> t;
        u --; v --;
        G[u].push_back({v, t});
    }

    vl potential(N, INFLL);
    potential[0] = 0;
    rep (_, N-1) {
        rep (n, N) {
            for (auto [v, c] : G[n]) {
                chmin(potential[v], potential[n]+c);
            }
        }
    }
    vvl dist(N, vl(N, INFLL));
    rep (n, N) {
        for (auto [v, c] : G[n]) {
            dist[n][v] = c+potential[n]-potential[v];
        }
    }
    
    vvl result(N, vl(N, INFLL));
    rep (s, N) {
        result[s][s] = 0;
        vector<bool> visited(N, false);
        priority_queue<pll, vector<pll>, greater<pll>> que;
        que.push({0, s});
        while (!que.empty()) {
            auto [d, n] = que.top(); que.pop();
            if (visited[n]) continue;
            visited[n] = true;
            for (auto [v, _] : G[n]) {
                if (result[s][n]+dist[n][v] < result[s][v]) {
                    result[s][v] = result[s][n]+dist[n][v];
                    que.push({result[s][v], v});
                }
            }
        }
        rep (i, N) {
            if (result[s][i] != INFLL) {
                result[s][i] += potential[i]-potential[s];
            }
        }
    }

    rep (i, N) {
        rep (j, N) {
            if (i == j) continue;
            if (result[i][j] != INFLL) {
                result[i][j] += P[i]+P[j];
            }
        }
    }

    ll MIN = INFLL;
    ll cnt = 0;
    rep (i, N) {
        rep (j, N) {
            if (i == j) continue;
            if (result[i][j] < MIN) {
                MIN = result[i][j];
                cnt = 1;
            } else if (result[i][j] == MIN) {
                cnt ++;
            }
        }
    }

    print(format("{} {}", MIN, cnt));
}
0