結果

問題 No.1382 Travel in Mitaru city
ユーザー んんんんんん
提出日時 2022-12-28 18:41:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 204,672 KB
最終ジャッジ日時 2025-02-09 21:20:40
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int N, M, S, T;
    cin >> N >> M >> S >> T;
    S--; T--;
    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];

    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    priority_queue<pair<int, int>> que;
    vector<bool> seen(N, false);
    seen[S] = true;

    for (auto nv : G[S]) {
        seen[nv] = true;
        que.emplace(p[nv], nv);
    }
    int ans = 0;
    int mini = p[S];
    while (!que.empty()) {
        auto pa = que.top();
        que.pop();
        int v = pa.second;

        if (pa.first < mini) {
            mini = pa.first;
            ans++;
        }
        for (auto nv : G[v]) {
            if (seen[nv]) continue;
            seen[nv] = true;
            que.emplace(p[nv], nv);
        }
    }

    cout << ans << endl;
}
0