結果

問題 No.2319 Friends+
ユーザー 沙耶花沙耶花
提出日時 2023-05-26 21:43:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 553 ms / 3,000 ms
コード長 1,358 bytes
コンパイル時間 4,430 ms
コンパイル使用メモリ 270,792 KB
実行使用メモリ 9,528 KB
最終ジャッジ日時 2023-08-26 10:59:38
合計ジャッジ時間 23,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 384 ms
7,876 KB
testcase_03 AC 388 ms
7,812 KB
testcase_04 AC 376 ms
7,880 KB
testcase_05 AC 378 ms
7,944 KB
testcase_06 AC 381 ms
7,908 KB
testcase_07 AC 357 ms
8,144 KB
testcase_08 AC 363 ms
8,148 KB
testcase_09 AC 355 ms
8,076 KB
testcase_10 AC 357 ms
8,192 KB
testcase_11 AC 350 ms
8,152 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 327 ms
8,400 KB
testcase_19 AC 363 ms
9,528 KB
testcase_20 AC 330 ms
8,080 KB
testcase_21 AC 334 ms
8,208 KB
testcase_22 AC 349 ms
8,164 KB
testcase_23 AC 353 ms
8,744 KB
testcase_24 AC 355 ms
8,264 KB
testcase_25 AC 350 ms
8,140 KB
testcase_26 AC 553 ms
8,084 KB
testcase_27 AC 467 ms
8,204 KB
testcase_28 AC 406 ms
8,080 KB
testcase_29 AC 362 ms
8,208 KB
testcase_30 AC 353 ms
8,204 KB
testcase_31 AC 333 ms
8,180 KB
testcase_32 AC 330 ms
8,200 KB
testcase_33 AC 326 ms
8,164 KB
testcase_34 AC 323 ms
8,088 KB
testcase_35 AC 333 ms
8,192 KB
testcase_36 AC 326 ms
7,944 KB
testcase_37 AC 341 ms
7,680 KB
testcase_38 AC 332 ms
8,144 KB
testcase_39 AC 338 ms
8,148 KB
testcase_40 AC 342 ms
8,080 KB
testcase_41 AC 338 ms
8,136 KB
testcase_42 AC 337 ms
8,164 KB
testcase_43 AC 337 ms
8,176 KB
testcase_44 AC 341 ms
8,176 KB
testcase_45 AC 352 ms
8,536 KB
testcase_46 AC 372 ms
7,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
#define sq 1300


int main(){
	int N,M;
	cin>>N>>M;
	
	vector<int> p(N);
	rep(i,N){
		cin>>p[i];
		p[i]--;
	}
	
	vector<vector<int>> E(N);
	rep(i,M){
		int u,v;
		scanf("%d %d",&u,&v);
		u--,v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	vector<int> big(N);
	rep(i,N){
		if(E[i].size()>sq)big[i] = 1;
	}
	
	vector<vector<int>> nE(N);
	rep(i,N){
		rep(j,E[i].size()){
			if(big[E[i][j]])nE[i].push_back(E[i][j]);
		}
	}
	
	vector<map<int,int>> mp(N);
	rep(i,N){
		rep(j,nE[i].size()){
			int to = nE[i][j];
			mp[to][p[i]]++;
		}
	}
	
	int q;
	cin>>q;
	rep(_,q){
		int a,b;
		scanf("%d %d",&a,&b);
		a--,b--;
		if(p[a]==p[b]){
			cout<<"No"<<endl;
			continue;
		}
		bool f = false;
		if(big[a]){
			if(mp[a].count(p[b]))f = true;
		}
		else{
			rep(i,E[a].size()){
				int to = E[a][i];
				if(p[to]==p[b])f = true;
			}
		}
		if(!f){
			cout<<"No"<<endl;
			continue;
		}
		cout<<"Yes"<<endl;
		rep(i,nE[a].size()){
			int to = nE[a][i];
			mp[to][p[a]]--;
			if(mp[to][p[a]]==0)mp[to].erase(p[a]);
		}
		p[a] = p[b];
		rep(i,nE[a].size()){
			int to = nE[a][i];
			mp[to][p[a]]++;
		}
	}
	
	return 0;
}
0