結果

問題 No.408 五輪ピック
ユーザー willowoooowillowoooo
提出日時 2016-08-21 17:24:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 1,723 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 79,868 KB
実行使用メモリ 9,980 KB
最終ジャッジ日時 2023-08-07 17:33:50
合計ジャッジ時間 2,944 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 24 ms
5,344 KB
testcase_06 AC 17 ms
5,608 KB
testcase_07 AC 25 ms
5,404 KB
testcase_08 AC 19 ms
4,740 KB
testcase_09 AC 20 ms
4,952 KB
testcase_10 AC 17 ms
5,152 KB
testcase_11 AC 16 ms
4,820 KB
testcase_12 AC 28 ms
5,432 KB
testcase_13 AC 24 ms
5,320 KB
testcase_14 AC 7 ms
4,384 KB
testcase_15 AC 30 ms
6,572 KB
testcase_16 AC 26 ms
5,152 KB
testcase_17 AC 28 ms
4,952 KB
testcase_18 AC 30 ms
5,396 KB
testcase_19 AC 31 ms
5,480 KB
testcase_20 AC 10 ms
4,832 KB
testcase_21 AC 6 ms
4,408 KB
testcase_22 AC 16 ms
5,572 KB
testcase_23 AC 45 ms
9,980 KB
testcase_24 AC 186 ms
8,480 KB
testcase_25 AC 51 ms
7,112 KB
testcase_26 AC 36 ms
5,984 KB
testcase_27 AC 127 ms
6,960 KB
testcase_28 AC 52 ms
5,612 KB
testcase_29 AC 130 ms
5,928 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> graph[20050];
	int A[50010] = { 0 }, B[50010] = { 0 };
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		A[i] = a, B[i] = b;
		
			graph[a].push_back(b);
			graph[b].push_back(a);
		}
		
	
	

	/*for (int i = 0; i <= N; i++)
	{
		cout << i << " " ;
		for (int j = 0; j < graph[i].size(); j++)
		{
			cout << graph[i][j]<<" ";
		}
		cout << endl;
	}
	*/
	vector<unordered_set<int>> p(N+1);
	for (int i = 0; i < graph[1].size(); i++)
	{
		int a = graph[1][i];
		for (int j = 0; j < graph[a].size(); j++)
		{
			int b = graph[a][j];
			if (b == 1)
				continue;
			p[b].insert(a);
			//cout << a << " " << b << endl;
		}
	}
/*	for (int i = 0; i  < p.size(); i++)
	{
		for (int j = i; j < p.size(); j++)
		{

			if (i == j)
				continue;
			int a1 = p[i].first, b1 = p[i].second, a2 = p[j].first, b2 = p[j].second;
			if (a1 == a2 || b1 == b2 || a2 == b1 || a1 == b2)
				continue;
			bool flag = false;
			for (int j = 0; j < graph[b1].size(); j++)
			{
				if (graph[b1][j] == b2)
					flag = true;
			}
			if (flag) {
				//	cout << a1 << " " << b1 << " " << a2 << " " << b2 << endl;
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	*/
	for (int i = 0; i < M; i++)
	{
		int c = A[i], d = B[i];
		for (int j = 0; j < graph[c].size(); j++)
		{
			if (d == graph[c][j]) {
				for (auto &s : p[c]) {
					for (auto &t : p[d]) {
						if (s != t && s != c && s != d && t!= c&&t != d) {
							cout << "YES" << endl;
							//cout << s << " " << t << " "<<c<<" "<<d<<endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0