結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 kmjpkmjp
提出日時 2021-02-09 00:27:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 209,336 KB
実行使用メモリ 11,604 KB
最終ジャッジ日時 2023-09-20 09:15:38
合計ジャッジ時間 12,856 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,704 KB
testcase_01 AC 4 ms
6,744 KB
testcase_02 AC 4 ms
6,812 KB
testcase_03 AC 4 ms
6,748 KB
testcase_04 AC 4 ms
6,872 KB
testcase_05 AC 5 ms
6,712 KB
testcase_06 AC 30 ms
8,296 KB
testcase_07 AC 23 ms
7,804 KB
testcase_08 AC 15 ms
7,212 KB
testcase_09 AC 30 ms
8,320 KB
testcase_10 AC 30 ms
8,416 KB
testcase_11 AC 52 ms
9,408 KB
testcase_12 AC 53 ms
9,448 KB
testcase_13 AC 58 ms
9,404 KB
testcase_14 AC 53 ms
9,584 KB
testcase_15 AC 52 ms
9,360 KB
testcase_16 AC 90 ms
11,168 KB
testcase_17 AC 92 ms
10,964 KB
testcase_18 AC 89 ms
11,028 KB
testcase_19 AC 89 ms
10,920 KB
testcase_20 AC 92 ms
11,036 KB
testcase_21 AC 84 ms
10,960 KB
testcase_22 AC 83 ms
10,924 KB
testcase_23 AC 91 ms
10,956 KB
testcase_24 AC 88 ms
10,944 KB
testcase_25 AC 91 ms
10,916 KB
testcase_26 AC 91 ms
10,992 KB
testcase_27 AC 89 ms
11,012 KB
testcase_28 AC 90 ms
10,992 KB
testcase_29 AC 92 ms
10,920 KB
testcase_30 AC 75 ms
11,052 KB
testcase_31 AC 65 ms
10,440 KB
testcase_32 AC 77 ms
11,236 KB
testcase_33 AC 76 ms
10,932 KB
testcase_34 AC 50 ms
9,600 KB
testcase_35 AC 34 ms
8,680 KB
testcase_36 AC 43 ms
10,808 KB
testcase_37 AC 10 ms
7,296 KB
testcase_38 AC 46 ms
11,288 KB
testcase_39 AC 15 ms
7,864 KB
testcase_40 AC 37 ms
10,132 KB
testcase_41 AC 37 ms
10,456 KB
testcase_42 AC 43 ms
11,008 KB
testcase_43 AC 39 ms
10,536 KB
testcase_44 AC 18 ms
8,204 KB
testcase_45 AC 36 ms
10,136 KB
testcase_46 AC 19 ms
8,264 KB
testcase_47 AC 63 ms
11,320 KB
testcase_48 AC 46 ms
10,016 KB
testcase_49 AC 67 ms
11,604 KB
testcase_50 AC 31 ms
8,836 KB
testcase_51 AC 63 ms
10,676 KB
testcase_52 AC 73 ms
11,172 KB
testcase_53 AC 18 ms
7,864 KB
testcase_54 AC 32 ms
8,804 KB
testcase_55 AC 72 ms
11,172 KB
testcase_56 AC 24 ms
8,016 KB
testcase_57 AC 46 ms
9,644 KB
testcase_58 AC 11 ms
7,280 KB
testcase_59 AC 23 ms
8,128 KB
testcase_60 AC 66 ms
10,912 KB
testcase_61 AC 5 ms
6,744 KB
testcase_62 AC 4 ms
6,748 KB
testcase_63 AC 10 ms
7,096 KB
testcase_64 AC 6 ms
6,808 KB
testcase_65 AC 5 ms
6,724 KB
testcase_66 AC 6 ms
6,820 KB
testcase_67 AC 5 ms
6,744 KB
testcase_68 AC 7 ms
6,696 KB
testcase_69 AC 6 ms
6,720 KB
testcase_70 AC 7 ms
6,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<101010> uf;
int N,M,S,T;
int P[101010];
pair<int,int> X[101010];
vector<int> E[101010];
int vis[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>S>>T;
	S--;
	FOR(i,N) {
		cin>>P[i];
		X[i]={-P[i],i};
	}
	FOR(i,N) if(P[i]>=P[S]) vis[i]=1;
	sort(X,X+N);
	FOR(i,M) {
		cin>>x>>y;
		x--,y--;
		E[x].push_back(y);
		E[y].push_back(x);
		if(P[x]>=P[S]&&P[y]>=P[S]) uf(x,y);
	}
	int pre=P[S],ret=0;
	FOR(i,N) {
		j=X[i].second;
		if(vis[j]) continue;
		vis[j]=1;
		FORR(e,E[j]) if(vis[e]) {
			uf(e,j);
			if(uf[j]==uf[S]&&P[j]<pre) {
				pre=P[j];
				ret++;
			}
		}
	}
	cout<<ret<<endl;
	
		
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0