結果

問題 No.1382 Travel in Mitaru city
コンテスト
ユーザー zjsdut
提出日時 2026-03-05 12:08:29
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 929 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,497 ms
コンパイル使用メモリ 222,500 KB
実行使用メモリ 10,488 KB
最終ジャッジ日時 2026-03-05 12:08:40
合計ジャッジ時間 9,275 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    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>> q;
    q.push({p[s], s});
    int minv = p[s];
    int ans = 0;
    vector<bool> done(n);
    while (!q.empty()) {
        auto [val, u] = q.top();
        q.pop();
        if (done[u]) continue;
        done[u] = true;
        if (val < minv) {
            minv = val;
            ans++;
        }
        for (int v : g[u]) {
            q.push({p[v], v});
        }
    }
    cout << ans << '\n';
}
0