結果

問題 No.1382 Travel in Mitaru city
ユーザー carrot46carrot46
提出日時 2021-02-07 20:55:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 2,420 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 176,364 KB
実行使用メモリ 12,148 KB
最終ジャッジ日時 2023-09-17 19:45:24
合計ジャッジ時間 7,420 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 27 ms
6,512 KB
testcase_07 AC 22 ms
5,580 KB
testcase_08 AC 14 ms
4,560 KB
testcase_09 AC 29 ms
6,396 KB
testcase_10 AC 28 ms
6,300 KB
testcase_11 AC 48 ms
8,916 KB
testcase_12 AC 49 ms
8,796 KB
testcase_13 AC 53 ms
9,060 KB
testcase_14 AC 45 ms
8,660 KB
testcase_15 AC 46 ms
8,532 KB
testcase_16 AC 78 ms
12,024 KB
testcase_17 AC 76 ms
11,988 KB
testcase_18 AC 77 ms
12,148 KB
testcase_19 AC 78 ms
12,016 KB
testcase_20 AC 79 ms
12,080 KB
testcase_21 AC 82 ms
11,948 KB
testcase_22 AC 83 ms
11,960 KB
testcase_23 AC 81 ms
12,016 KB
testcase_24 AC 76 ms
12,092 KB
testcase_25 AC 77 ms
12,084 KB
testcase_26 AC 67 ms
12,012 KB
testcase_27 AC 66 ms
11,888 KB
testcase_28 AC 70 ms
12,020 KB
testcase_29 AC 70 ms
12,088 KB
testcase_30 AC 70 ms
12,084 KB
testcase_31 AC 58 ms
10,412 KB
testcase_32 AC 69 ms
11,636 KB
testcase_33 AC 64 ms
11,128 KB
testcase_34 AC 43 ms
8,536 KB
testcase_35 AC 28 ms
6,800 KB
testcase_36 AC 40 ms
10,124 KB
testcase_37 AC 7 ms
4,392 KB
testcase_38 AC 44 ms
11,024 KB
testcase_39 AC 13 ms
5,228 KB
testcase_40 AC 33 ms
9,188 KB
testcase_41 AC 38 ms
9,588 KB
testcase_42 AC 44 ms
11,236 KB
testcase_43 AC 38 ms
10,168 KB
testcase_44 AC 16 ms
5,944 KB
testcase_45 AC 36 ms
9,504 KB
testcase_46 AC 16 ms
5,788 KB
testcase_47 AC 54 ms
11,476 KB
testcase_48 AC 38 ms
9,032 KB
testcase_49 AC 58 ms
12,136 KB
testcase_50 AC 26 ms
7,308 KB
testcase_51 AC 60 ms
10,504 KB
testcase_52 AC 72 ms
11,820 KB
testcase_53 AC 16 ms
5,088 KB
testcase_54 AC 30 ms
6,952 KB
testcase_55 AC 69 ms
11,172 KB
testcase_56 AC 22 ms
5,892 KB
testcase_57 AC 43 ms
8,528 KB
testcase_58 AC 8 ms
4,376 KB
testcase_59 AC 20 ms
5,748 KB
testcase_60 AC 66 ms
11,128 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 7 ms
4,376 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 3 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 4 ms
4,380 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

class union_find{
        vector<long> parent, tree_size;
    public:
        union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
            for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
        }
        ll find(ll x){
            while(parent[x] != x)x = parent[x] = parent[parent[x]];
            return x;
        }
        void merge(ll a, ll b){
            a = find(a);
            b = find(b);
	    if(a==b) return;
            if(tree_size[a] < tree_size[b])swap(a, b);
            tree_size[a] += tree_size[b];
            parent[b] = a;
            return;
        }
	bool same(ll a, ll b){
	    a = find(a);
	    b = find(b);
	    return a == b;
	}
    };
//uf.mergeのように使う
//ufはMAX_N+1でとるか、代入時に0-indexedにする

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N>>M;
    int s, t; cin>>s>>t;
    --s; --t;
    vec p(N), ord(N);
    mat G(N);
    rep(i, N) cin>>p[i];
    rep(i, M){
        int a, b; cin>>a>>b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    union_find uf(N);
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](int x, int y){
        return p[x] > p[y];
    });
    ll X = p[s], res = 0;
    rep(i, N){
        int v = ord[i];
        //cout<<v<<endl;
        for(int to : G[v]){
            if(p[v] <= p[to]) uf.merge(v, to);
        }
        if(uf.same(s, v)) res += chmin(X, p[v]);
        //rep(j, N) rep(k, N) cout<<uf.same(j, k)<<" \n"[k == N - 1];
    }
    cout<<res<<endl;
}
0