結果

問題 No.408 五輪ピック
ユーザー snrnsidy
提出日時 2021-06-15 01:35:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 1,218 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 199,704 KB
最終ジャッジ日時 2025-01-22 08:21:30
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

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