結果

問題 No.2319 Friends+
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-04 18:08:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 3,869 ms
コンパイル使用メモリ 214,936 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-04 18:08:46
合計ジャッジ時間 31,685 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 471 ms
6,676 KB
testcase_05 WA -
testcase_06 AC 478 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 494 ms
6,676 KB
testcase_19 AC 477 ms
6,676 KB
testcase_20 AC 503 ms
6,676 KB
testcase_21 AC 508 ms
6,676 KB
testcase_22 AC 511 ms
6,676 KB
testcase_23 AC 473 ms
6,676 KB
testcase_24 AC 480 ms
6,676 KB
testcase_25 AC 477 ms
6,676 KB
testcase_26 AC 485 ms
6,676 KB
testcase_27 AC 497 ms
6,676 KB
testcase_28 AC 498 ms
6,676 KB
testcase_29 AC 504 ms
6,676 KB
testcase_30 AC 501 ms
6,676 KB
testcase_31 AC 506 ms
6,676 KB
testcase_32 AC 529 ms
6,676 KB
testcase_33 AC 518 ms
6,676 KB
testcase_34 AC 532 ms
6,676 KB
testcase_35 AC 532 ms
6,676 KB
testcase_36 AC 494 ms
6,676 KB
testcase_37 AC 465 ms
6,676 KB
testcase_38 AC 474 ms
6,676 KB
testcase_39 AC 473 ms
6,676 KB
testcase_40 AC 481 ms
6,676 KB
testcase_41 AC 478 ms
6,676 KB
testcase_42 AC 480 ms
6,676 KB
testcase_43 AC 505 ms
6,676 KB
testcase_44 AC 477 ms
6,676 KB
testcase_45 AC 482 ms
6,676 KB
testcase_46 AC 480 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
int main() {
	int N, M;cin >> N >> M;
	dsu uf(N);
	vector<int> P(N);
	for (int i = 0;i < N;i++) cin >> P[i];
	for (int i = 0;i < M;i++) {
		int a, b;cin >> a >> b;
		a--;b--;
		uf.merge(a, b);
	}
	int Q;cin >> Q;
	vector<multiset<int>> C(N + 1);
	for (int v = 0;v < N;v++) C[P[v]].insert(uf.leader(v));
	while (Q--) {
		int x, y;cin >> x >> y;x--;y--;
		if (P[x] == P[y]) {
			cout << "No" << endl;
			continue;
		}
		int rx = uf.leader(x);
		int px = P[x];int py = P[y];
		if (C[py].find(rx) == C[py].end()) {
			cout << "No" << endl;
			continue;
		}
		C[py].insert(rx);
		C[px].erase(C[px].find(rx));
		P[x] = py;
		cout << "Yes" << endl;
	}
}
0