結果

問題 No.408 五輪ピック
ユーザー snrnsidysnrnsidy
提出日時 2021-06-15 01:35:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 1,218 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 205,672 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-08-26 16:01:52
合計ジャッジ時間 4,190 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 52 ms
4,376 KB
testcase_07 AC 54 ms
4,376 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 55 ms
4,376 KB
testcase_11 AC 53 ms
4,380 KB
testcase_12 AC 62 ms
4,460 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 22 ms
4,376 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 16 ms
4,376 KB
testcase_22 AC 44 ms
4,376 KB
testcase_23 AC 13 ms
4,568 KB
testcase_24 AC 51 ms
4,476 KB
testcase_25 AC 47 ms
4,376 KB
testcase_26 AC 115 ms
4,376 KB
testcase_27 AC 154 ms
4,376 KB
testcase_28 AC 27 ms
4,376 KB
testcase_29 AC 78 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

// 1 b c d e 1
int N, M, u, v;
bool check[20005];
vector <pair<int, int>> E;
vector <int> adj[20005];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> M;

	for (int i = 0; i < M; i++)
	{
		cin >> u >> v;
		E.push_back(make_pair(u, v));
		if (u == 1)
		{
			check[v] = true;
		}
		if (v == 1)
		{
			check[u] = true;
		}
	}

	for (int i = 0; i < M; i++)
	{
		u = E[i].first;
		v = E[i].second;
		if (check[u] && v!=1)
		{
			adj[v].push_back(u);
		}
		if (check[v] && u!=1)
		{
			adj[u].push_back(v);
		}
	}
	
	for (int i = 0; i < M; i++)
	{
		bitset <20005> check1, check2, temp;
		u = E[i].first;
		v = E[i].second;
		if (u == 1 || v == 1) continue;
		for (auto k : adj[u])
		{
			if (k == u || k == v || k==1) continue;
			check1[k] = true;
		}
		for (auto k : adj[v])
		{
			if (k == u || k == v || k==1) continue;
			check2[k] = true;
		}
		if (check1.count() == 1 && check2.count() == 1)
		{
			temp = (check1 & check2);
			if (temp.none())
			{
				cout << "YES" << '\n';
				return 0;
			}
		}
		else if (check1.count() >= 1 && check2.count() >= 1)
		{
			cout << "YES" << '\n';
			return 0;
		}
	}
	cout << "NO" << '\n';
	return 0;
}
0