結果

問題 No.2319 Friends+
ユーザー 00 Sakuda
提出日時 2024-04-04 18:45:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 938 ms / 3,000 ms
コード長 683 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 197,184 KB
最終ジャッジ日時 2025-02-20 20:07:16
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
	int MN = 2e4;
	int N, M;cin >> N >> M;
	vector<bitset<(int)2e4>> S(N);
	vector<bitset<(int)2e4>> T(N);
	vector<int> P(N);
	for (int i = 0;i < N;i++) {
		cin >> P[i];
		P[i]--;
		T[P[i]].set(i);
	}
	for (int i = 0;i < M;i++) {
		int a, b;cin >> a >> b;
		a--;b--;
		S[a].set(b);
		S[b].set(a);
	}
	int Q;cin >> Q;
	while (Q--) {
		int x, y;cin >> x >> y;x--;y--;
		if (P[x] == P[y]) {
			cout << "No" << endl;
			continue;
		}
		int px = P[x];int py = P[y];
		auto res = S[x] & T[py];
		if (!res.any()) {
			cout << "No" << endl;
			continue;
		}
		T[py].set(x);
		T[px].reset(x);
		P[x] = py;
		cout << "Yes" << endl;
	}
}
0