結果

問題 No.2319 Friends+
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-05-28 19:47:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,635 ms / 3,000 ms
コード長 1,058 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 204,948 KB
最終ジャッジ日時 2025-02-13 15:50:48
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf(" %d %d", &N, &M);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:7:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         for (auto& a : A) scanf(" %d", &a);
      |                           ~~~~~^~~~~~~~~~~
main.cpp:11:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |                 scanf(" %d %d", &a, &b);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         scanf(" %d", &Q);
      |         ~~~~~^~~~~~~~~~~
main.cpp:33:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |                 scanf(" %d %d", &x, &y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
	int N, M;
	scanf(" %d %d", &N, &M);
	std::vector<int> A(N);
	for (auto& a : A) scanf(" %d", &a);
	vector<vector<int>> gr(N);
	for (int i = 0; i < M; i ++) {
		int a, b;
		scanf(" %d %d", &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;
	scanf(" %d", &Q);
	while (Q--) {
		int x, y;
		scanf(" %d %d", &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