結果

問題 No.1382 Travel in Mitaru city
ユーザー okok
提出日時 2021-02-07 21:00:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,292 bytes
コンパイル時間 1,063 ms
コンパイル使用メモリ 93,448 KB
実行使用メモリ 12,936 KB
最終ジャッジ日時 2023-09-17 19:53:31
合計ジャッジ時間 7,044 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 28 ms
6,328 KB
testcase_07 AC 23 ms
5,684 KB
testcase_08 AC 13 ms
4,400 KB
testcase_09 AC 30 ms
6,500 KB
testcase_10 AC 29 ms
6,328 KB
testcase_11 AC 49 ms
9,248 KB
testcase_12 AC 50 ms
9,344 KB
testcase_13 AC 56 ms
9,772 KB
testcase_14 AC 50 ms
9,160 KB
testcase_15 AC 49 ms
9,196 KB
testcase_16 AC 84 ms
12,804 KB
testcase_17 AC 83 ms
12,804 KB
testcase_18 AC 83 ms
12,624 KB
testcase_19 AC 83 ms
12,856 KB
testcase_20 AC 82 ms
12,780 KB
testcase_21 AC 81 ms
12,632 KB
testcase_22 AC 83 ms
12,652 KB
testcase_23 AC 84 ms
12,936 KB
testcase_24 AC 82 ms
12,632 KB
testcase_25 AC 84 ms
12,624 KB
testcase_26 AC 81 ms
12,848 KB
testcase_27 AC 82 ms
12,784 KB
testcase_28 AC 84 ms
12,648 KB
testcase_29 AC 83 ms
12,856 KB
testcase_30 AC 74 ms
12,856 KB
testcase_31 AC 63 ms
10,940 KB
testcase_32 AC 80 ms
12,488 KB
testcase_33 AC 74 ms
11,800 KB
testcase_34 AC 48 ms
8,900 KB
testcase_35 AC 31 ms
7,236 KB
testcase_36 AC 42 ms
10,820 KB
testcase_37 AC 8 ms
4,392 KB
testcase_38 AC 46 ms
11,780 KB
testcase_39 AC 13 ms
5,356 KB
testcase_40 AC 35 ms
9,804 KB
testcase_41 AC 43 ms
10,324 KB
testcase_42 AC 52 ms
11,900 KB
testcase_43 AC 45 ms
10,788 KB
testcase_44 AC 18 ms
6,152 KB
testcase_45 AC 41 ms
10,020 KB
testcase_46 AC 17 ms
5,716 KB
testcase_47 AC 62 ms
12,180 KB
testcase_48 AC 47 ms
9,464 KB
testcase_49 AC 68 ms
12,752 KB
testcase_50 AC 31 ms
7,608 KB
testcase_51 AC 62 ms
11,012 KB
testcase_52 AC 76 ms
12,592 KB
testcase_53 AC 17 ms
5,252 KB
testcase_54 AC 31 ms
7,272 KB
testcase_55 AC 71 ms
12,024 KB
testcase_56 AC 22 ms
6,248 KB
testcase_57 AC 44 ms
9,296 KB
testcase_58 AC 8 ms
4,376 KB
testcase_59 AC 21 ms
6,252 KB
testcase_60 AC 68 ms
12,004 KB
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 7 ms
4,380 KB
testcase_64 AC 4 ms
4,384 KB
testcase_65 AC 1 ms
4,376 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 4 ms
4,380 KB
testcase_69 AC 3 ms
4,380 KB
testcase_70 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


class union_find
{
	int  _setnum;
	vector<int> par, nume;
public:
	union_find(){
	}
	
	union_find(int x){
		par.resize(x);
		nume.resize(x);
		init();
	}
	
	~union_find(){
		//
		
	}
	
	void clear(){
		_setnum = 0;
		par.clear();
		nume.clear();
	}
	
	void init(){
		_setnum = par.size();
		for(int i = 0; i < par.size(); i++){
			par[i] = i;
			nume[i] = 1;
		}
	}
	
	void resize(int x){
		
		par.resize(x);
		nume.resize(x);
		init();
	}

	int find(int x){
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
	
		if(x == y)return;
		
		_setnum--;
		
		if(nume[x] > nume[y]) std::swap(x,y);
		
		par[x] = y;
		nume[y] += nume[x];
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	int numel(int x){
		return nume[find(x)];
	}
	
	int size(){
		return par.size();
	}
	
	int setnum(){
		return _setnum;
	}
};

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, M, S, T;
    int X, Y = 0;
	vector<int> p;
	vector<pair<int,int>> num;
    vector<vector<int>> G;
    union_find uf;
    
    cin>>N>>M>>S>>T;
    
    S--, T--;
    
    
	
    p.resize(N);
    uf.resize(N);
    G.resize(N);
    
    for(int i = 0; i < N; i++){
        cin>>p[i];
        num.push_back({p[i], i});
    }
    
    X = p[S];
    
    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);
    }
    
    sort(num.begin(), num.end(), greater<pair<int,int>>());
    
    for(int i = 0; i < num.size(); i++){
        for(int y : G[num[i].second]){
            if(p[y] < num[i].first) continue;
            uf.unite(num[i].second, y);
            
            if(uf.same(num[i].second, S) && num[i].first < X) {
                Y++;
                X = num[i].first;
            }                
        }
    }
    
    cout<<Y<<endl;
    
	return 0;
}
0