結果

問題 No.2319 Friends+
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-05-28 19:40:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,718 ms / 3,000 ms
コード長 1,012 bytes
コンパイル時間 4,163 ms
コンパイル使用メモリ 209,792 KB
実行使用メモリ 169,112 KB
最終ジャッジ日時 2023-08-27 15:31:20
合計ジャッジ時間 33,356 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 572 ms
13,496 KB
testcase_03 AC 556 ms
13,352 KB
testcase_04 AC 531 ms
13,196 KB
testcase_05 AC 520 ms
13,440 KB
testcase_06 AC 524 ms
13,440 KB
testcase_07 AC 811 ms
34,048 KB
testcase_08 AC 831 ms
34,212 KB
testcase_09 AC 834 ms
34,080 KB
testcase_10 AC 853 ms
34,200 KB
testcase_11 AC 863 ms
34,156 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 455 ms
11,204 KB
testcase_19 AC 598 ms
24,968 KB
testcase_20 AC 807 ms
22,196 KB
testcase_21 AC 635 ms
19,692 KB
testcase_22 AC 1,107 ms
23,756 KB
testcase_23 AC 593 ms
25,104 KB
testcase_24 AC 577 ms
25,232 KB
testcase_25 AC 593 ms
25,132 KB
testcase_26 AC 585 ms
24,872 KB
testcase_27 AC 598 ms
24,840 KB
testcase_28 AC 2,718 ms
29,240 KB
testcase_29 AC 1,662 ms
25,284 KB
testcase_30 AC 1,092 ms
23,908 KB
testcase_31 AC 791 ms
22,008 KB
testcase_32 AC 628 ms
19,204 KB
testcase_33 AC 520 ms
15,596 KB
testcase_34 AC 472 ms
13,404 KB
testcase_35 AC 459 ms
11,816 KB
testcase_36 AC 1,560 ms
169,112 KB
testcase_37 AC 1,624 ms
18,664 KB
testcase_38 AC 646 ms
25,488 KB
testcase_39 AC 651 ms
25,228 KB
testcase_40 AC 646 ms
25,228 KB
testcase_41 AC 735 ms
25,356 KB
testcase_42 AC 800 ms
25,532 KB
testcase_43 AC 966 ms
25,176 KB
testcase_44 AC 1,302 ms
26,052 KB
testcase_45 AC 1,875 ms
23,040 KB
testcase_46 AC 444 ms
16,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
	int N, M;
	cin >> N >> M;
	std::vector<int> A(N);
	for (auto& a : A) cin >> a;
	vector<vector<int>> gr(N);
	for (int i = 0; i < M; i ++) {
		int a, b;
		cin >> a >> b;
		gr[--a].push_back(--b);
		gr[b].push_back(a);
	}
	int s = max(1, (int)sqrt(M));
	vector<vector<int>> bb(N);
	vector<unordered_map<int, int>> X(N);
	for (int i = 0; i < N; i ++) {
		if (gr[i].size() > s) {
			for (auto v : gr[i]) {
				bb[v].push_back(i);
			}
		} else {
			for (auto v : gr[i]) {
				X[v][A[i]] ++;
			}
		}
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int x, y;
		cin >> x >> y;
		x --; y --;
		if (A[x] == A[y]) {
			puts("No");
			continue;
		}
		int a = A[y];
		bool ok = false;
		if (X[x][a] > 0) {
			ok = true;
		} else {
			for (auto v : bb[x]) {
				ok = ok || (a == A[v]);
			}
		}
		if (ok) {
			puts("Yes");
			if (gr[x].size() <= s) {
				for (auto v : gr[x]) {
					X[v][A[x]] --;
					X[v][a] ++;
				}
			}
			A[x] = a;
		} else {
			puts("No");
		}
	}
}
0