結果

問題 No.1382 Travel in Mitaru city
ユーザー okok
提出日時 2021-02-07 20:56:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,246 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 93,460 KB
実行使用メモリ 12,992 KB
最終ジャッジ日時 2023-09-17 19:46:05
合計ジャッジ時間 6,892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 22 ms
5,492 KB
testcase_08 WA -
testcase_09 AC 31 ms
6,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 82 ms
12,636 KB
testcase_28 AC 81 ms
12,812 KB
testcase_29 AC 81 ms
12,616 KB
testcase_30 AC 75 ms
12,696 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 43 ms
10,940 KB
testcase_37 AC 8 ms
4,380 KB
testcase_38 AC 47 ms
11,780 KB
testcase_39 AC 13 ms
5,224 KB
testcase_40 AC 36 ms
9,696 KB
testcase_41 AC 44 ms
10,508 KB
testcase_42 AC 52 ms
11,912 KB
testcase_43 AC 45 ms
10,776 KB
testcase_44 AC 19 ms
6,228 KB
testcase_45 AC 41 ms
9,884 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 43 ms
9,492 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 7 ms
4,376 KB
testcase_64 AC 3 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 3 ms
4,380 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 4 ms
4,376 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]){
            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