結果

問題 No.2319 Friends+
ユーザー 沙耶花沙耶花
提出日時 2023-05-26 21:41:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,335 bytes
コンパイル時間 4,855 ms
コンパイル使用メモリ 269,704 KB
実行使用メモリ 29,000 KB
最終ジャッジ日時 2023-08-26 10:54:03
合計ジャッジ時間 41,165 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1,877 ms
28,888 KB
testcase_03 AC 1,788 ms
28,928 KB
testcase_04 AC 1,575 ms
28,888 KB
testcase_05 AC 1,727 ms
28,940 KB
testcase_06 AC 1,795 ms
29,000 KB
testcase_07 AC 475 ms
8,088 KB
testcase_08 AC 495 ms
8,212 KB
testcase_09 AC 464 ms
8,084 KB
testcase_10 AC 465 ms
8,168 KB
testcase_11 AC 469 ms
8,128 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 456 ms
8,304 KB
testcase_19 AC 468 ms
9,452 KB
testcase_20 AC 448 ms
8,072 KB
testcase_21 AC 448 ms
8,084 KB
testcase_22 AC 455 ms
8,180 KB
testcase_23 AC 440 ms
8,556 KB
testcase_24 AC 455 ms
8,040 KB
testcase_25 AC 467 ms
8,068 KB
testcase_26 AC 467 ms
8,076 KB
testcase_27 AC 463 ms
8,096 KB
testcase_28 AC 503 ms
8,148 KB
testcase_29 AC 469 ms
8,040 KB
testcase_30 AC 461 ms
8,128 KB
testcase_31 AC 434 ms
8,188 KB
testcase_32 AC 430 ms
8,032 KB
testcase_33 AC 452 ms
8,088 KB
testcase_34 AC 438 ms
8,168 KB
testcase_35 AC 446 ms
8,128 KB
testcase_36 AC 459 ms
7,824 KB
testcase_37 AC 2,836 ms
20,280 KB
testcase_38 AC 446 ms
8,088 KB
testcase_39 AC 428 ms
8,072 KB
testcase_40 AC 418 ms
8,036 KB
testcase_41 AC 433 ms
8,088 KB
testcase_42 AC 445 ms
8,068 KB
testcase_43 AC 443 ms
8,088 KB
testcase_44 AC 443 ms
8,032 KB
testcase_45 TLE -
testcase_46 AC 2,792 ms
19,296 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 500


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;
		cin>>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;
		cin>>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