結果

問題 No.408 五輪ピック
ユーザー willowoooowillowoooo
提出日時 2016-08-21 16:44:19
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,598 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 78,128 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-25 11:09:08
合計ジャッジ時間 5,752 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 7 ms
5,376 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 9 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 14 ms
5,504 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> graph[20010];
	int A[20010],B[20010];
	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);
	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) {
							cout << "YES" << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0