結果

問題 No.2319 Friends+
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-04 18:45:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 790 ms / 3,000 ms
コード長 683 bytes
コンパイル時間 2,838 ms
コンパイル使用メモリ 206,508 KB
実行使用メモリ 101,248 KB
最終ジャッジ日時 2024-04-04 18:46:15
合計ジャッジ時間 31,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 571 ms
101,248 KB
testcase_03 AC 574 ms
101,248 KB
testcase_04 AC 573 ms
101,248 KB
testcase_05 AC 563 ms
101,248 KB
testcase_06 AC 570 ms
101,248 KB
testcase_07 AC 779 ms
101,248 KB
testcase_08 AC 757 ms
101,248 KB
testcase_09 AC 790 ms
101,248 KB
testcase_10 AC 761 ms
101,248 KB
testcase_11 AC 776 ms
101,248 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 610 ms
101,248 KB
testcase_19 AC 665 ms
101,248 KB
testcase_20 AC 587 ms
101,248 KB
testcase_21 AC 601 ms
101,248 KB
testcase_22 AC 588 ms
101,248 KB
testcase_23 AC 622 ms
101,248 KB
testcase_24 AC 618 ms
101,248 KB
testcase_25 AC 609 ms
101,248 KB
testcase_26 AC 598 ms
101,248 KB
testcase_27 AC 612 ms
101,248 KB
testcase_28 AC 590 ms
101,248 KB
testcase_29 AC 601 ms
101,248 KB
testcase_30 AC 588 ms
101,248 KB
testcase_31 AC 588 ms
101,248 KB
testcase_32 AC 607 ms
101,248 KB
testcase_33 AC 586 ms
101,248 KB
testcase_34 AC 583 ms
101,248 KB
testcase_35 AC 598 ms
101,248 KB
testcase_36 AC 686 ms
101,248 KB
testcase_37 AC 539 ms
101,248 KB
testcase_38 AC 574 ms
101,248 KB
testcase_39 AC 574 ms
101,248 KB
testcase_40 AC 572 ms
101,248 KB
testcase_41 AC 606 ms
101,248 KB
testcase_42 AC 588 ms
101,248 KB
testcase_43 AC 590 ms
101,248 KB
testcase_44 AC 577 ms
101,248 KB
testcase_45 AC 576 ms
101,248 KB
testcase_46 AC 548 ms
101,248 KB
権限があれば一括ダウンロードができます

ソースコード

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