結果

問題 No.408 五輪ピック
ユーザー kurenai3110kurenai3110
提出日時 2016-10-18 18:08:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 71,368 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 02:40:57
合計ジャッジ時間 3,349 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 27 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 26 ms
5,376 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 21 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 16 ms
5,376 KB
testcase_12 AC 28 ms
5,376 KB
testcase_13 AC 25 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 30 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 30 ms
5,376 KB
testcase_18 AC 31 ms
5,376 KB
testcase_19 AC 34 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 16 ms
5,376 KB
testcase_23 AC 37 ms
5,376 KB
testcase_24 AC 24 ms
5,376 KB
testcase_25 AC 38 ms
5,376 KB
testcase_26 AC 35 ms
5,376 KB
testcase_27 AC 44 ms
5,376 KB
testcase_28 AC 371 ms
5,376 KB
testcase_29 AC 370 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N, M;

struct Node {
	int cnt=INT32_MAX;
};

int main()
{
	cin >> N >> M;
	vector<vector<int> > G(N+1);
	vector<Node> node(N + 1); node[1].cnt = 0;
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue<int> que;
	for (int i = 0; i < G[1].size(); i++) {
		que.push(G[1][i]);
		node[G[1][i]].cnt = node[1].cnt + 1;
	}

	bool flag = false;
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int i = 0; i < G[p].size(); i++) {
			if (node[p].cnt == 3)continue;
			if (node[G[p][i]].cnt == 2 && node[p].cnt == 2) flag = true;
			if (node[G[p][i]].cnt < node[p].cnt)continue;
			que.push(G[p][i]);
			node[G[p][i]].cnt = node[p].cnt + 1;
		}
	}
	if (flag)cout << "YES" << endl;
	else cout << "NO" << endl;

    return 0;
}

0