結果

問題 No.1382 Travel in Mitaru city
ユーザー ぷらぷら
提出日時 2021-02-07 21:45:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,937 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 182,932 KB
実行使用メモリ 11,548 KB
最終ジャッジ日時 2023-09-17 21:08:34
合計ジャッジ時間 9,665 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 68 ms
5,016 KB
testcase_07 AC 44 ms
4,532 KB
testcase_08 AC 22 ms
4,384 KB
testcase_09 AC 62 ms
5,228 KB
testcase_10 AC 72 ms
5,200 KB
testcase_11 AC 87 ms
7,480 KB
testcase_12 AC 86 ms
7,660 KB
testcase_13 AC 91 ms
7,596 KB
testcase_14 AC 81 ms
7,264 KB
testcase_15 AC 83 ms
7,220 KB
testcase_16 AC 132 ms
10,292 KB
testcase_17 AC 138 ms
10,088 KB
testcase_18 AC 134 ms
10,432 KB
testcase_19 AC 132 ms
9,960 KB
testcase_20 AC 136 ms
10,168 KB
testcase_21 AC 126 ms
9,640 KB
testcase_22 AC 127 ms
9,708 KB
testcase_23 AC 136 ms
9,856 KB
testcase_24 AC 141 ms
10,044 KB
testcase_25 AC 125 ms
9,772 KB
testcase_26 AC 116 ms
9,444 KB
testcase_27 AC 120 ms
10,180 KB
testcase_28 AC 119 ms
9,640 KB
testcase_29 AC 117 ms
9,324 KB
testcase_30 AC 119 ms
9,440 KB
testcase_31 AC 90 ms
8,704 KB
testcase_32 WA -
testcase_33 AC 104 ms
9,172 KB
testcase_34 AC 72 ms
7,380 KB
testcase_35 AC 49 ms
5,908 KB
testcase_36 AC 87 ms
8,652 KB
testcase_37 AC 14 ms
4,380 KB
testcase_38 AC 97 ms
9,120 KB
testcase_39 AC 26 ms
4,684 KB
testcase_40 AC 73 ms
7,916 KB
testcase_41 AC 81 ms
8,340 KB
testcase_42 AC 98 ms
9,444 KB
testcase_43 AC 87 ms
8,540 KB
testcase_44 AC 35 ms
5,272 KB
testcase_45 AC 78 ms
8,072 KB
testcase_46 AC 30 ms
5,324 KB
testcase_47 AC 107 ms
10,620 KB
testcase_48 AC 77 ms
8,616 KB
testcase_49 AC 113 ms
11,548 KB
testcase_50 AC 57 ms
7,360 KB
testcase_51 AC 91 ms
8,652 KB
testcase_52 AC 106 ms
9,648 KB
testcase_53 AC 25 ms
4,756 KB
testcase_54 AC 49 ms
6,196 KB
testcase_55 AC 103 ms
9,644 KB
testcase_56 AC 33 ms
5,264 KB
testcase_57 AC 68 ms
7,272 KB
testcase_58 AC 11 ms
4,384 KB
testcase_59 AC 32 ms
5,156 KB
testcase_60 AC 98 ms
9,060 KB
testcase_61 AC 4 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 14 ms
4,384 KB
testcase_64 AC 5 ms
4,384 KB
testcase_65 AC 2 ms
4,384 KB
testcase_66 AC 3 ms
4,384 KB
testcase_67 AC 4 ms
4,384 KB
testcase_68 AC 6 ms
4,380 KB
testcase_69 AC 3 ms
4,380 KB
testcase_70 AC 8 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define rrep(i,n) for(int i = int(n)-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template<class T> bool chmax(T &a, const T &b) {if(a < b) {a = b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b) {if(b < a) {a = b; return true;} return false;}
int dx[] = {1, 0,-1, 0, 1, 1,-1,-1};
int dy[] = {0, 1, 0,-1, 1,-1, 1,-1};
ll mod = 998244353;
ll MOD = 1000000007;
ll inf = 1001001001;
ll INF = 1001001001001001001;
struct UnionFind {
    vector<int>par;
    vector<int>size;
    UnionFind(int x) {
        par.resize(x);
        size.resize(x, 1);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if(par[x] == x) {
            return x;
        }
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) {
            return;
        }
        if(size[x] < size[y]) {
            par[x] = y;
            size[y] += size[x];
        }
        else {
            par[y] = x;
            size[x] += size[y];
        }
    }
};
int main() {
    int N,M,S,T;
    cin >> N >> M >> S >> T;
    S--;T--;
    vector<int>p(N);
    rep(i,N) {
        cin >> p[i];
    }
    vector<vector<int>>road(N);
    rep(i,M) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        road[a].pb(b);
        road[b].pb(a);
    }
    queue<int>que;
    que.push(S);
    UnionFind uf(N);
    int res = p[S];
    int ans = 0;
    set<pair<int,int>>st;
    while(true) {
        while (!que.empty()) {
            int x = que.front();
            que.pop();
            rep(i,road[x].size()) {
                if(p[road[x][i]] >= res) {
                    if(!uf.same(x,road[x][i])) {
                        uf.unite(x,road[x][i]);
                        que.push(road[x][i]);
                    }
                }
                else {
                    uf.unite(x,road[x][i]);
                    st.insert({p[road[x][i]],road[x][i]});
                }
            }
        }
        if(st.size() == 0) {
            break;
        }
        else {
            ans++;
            pair<int,int> x = *st.rbegin();
            auto it = st.end();
            it--;
            while(true) {
                if(it->first != x.first) {
                    break;
                }
                que.push(x.second);
                if(it == st.begin()){
                    st.erase(it);
                    break;
                }
                st.erase(it--);
            }
            chmin(res,x.first);
        }
    }
    cout << ans << endl;
}
0