結果

問題 No.1382 Travel in Mitaru city
ユーザー RheoTommy
提出日時 2021-02-07 23:09:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 1,248 bytes
コンパイル時間 2,625 ms
コンパイル使用メモリ 206,736 KB
最終ジャッジ日時 2025-01-18 15:50:01
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 68
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int) n; i++)

using ll = long long;
using namespace std;
using T = tuple<ll, ll, ll>;
using P = pair<ll, ll>;

const long long INF = 1ll << 60;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main() {
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];
    vector<vector<ll>> vertex(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        vertex[a].push_back(b);
        vertex[b].push_back(a);
    }
    
    ll ans = 0;
    ll x = p[s];
    set<ll> st;
    priority_queue<P> pri;
    st.insert(s);
    pri.emplace(p[s], s);
    while (!pri.empty()) {
        auto[pi, i] = pri.top();
        pri.pop();
        if (x > pi) {
            ans++;
            x = p[i];
        }
        for (auto j:vertex[i]) {
            if (st.find(j) == st.end()) {
                st.insert(j);
                pri.emplace(p[j], j);
            }
        }
    }
    
    cout << ans << endl;
}
0