結果

問題 No.408 五輪ピック
ユーザー kurenai3110kurenai3110
提出日時 2016-10-18 18:35:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 465 ms / 5,000 ms
コード長 1,120 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 72,912 KB
実行使用メモリ 4,896 KB
最終ジャッジ日時 2023-08-14 14:39:08
合計ジャッジ時間 3,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 24 ms
4,380 KB
testcase_06 AC 14 ms
4,488 KB
testcase_07 AC 20 ms
4,404 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 14 ms
4,380 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 22 ms
4,384 KB
testcase_13 AC 22 ms
4,384 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 28 ms
4,380 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 25 ms
4,384 KB
testcase_19 AC 26 ms
4,380 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 5 ms
4,384 KB
testcase_22 AC 12 ms
4,376 KB
testcase_23 AC 29 ms
4,896 KB
testcase_24 AC 19 ms
4,808 KB
testcase_25 AC 35 ms
4,384 KB
testcase_26 AC 29 ms
4,752 KB
testcase_27 AC 41 ms
4,508 KB
testcase_28 AC 450 ms
4,380 KB
testcase_29 AC 465 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N, M;

struct Node {
	int cnt=INT32_MAX;
	int from;
	int from_cnt = 0;
};

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]].from = 1;
		node[G[1][i]].from_cnt++;
		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 && (node[G[p][i]].from!=node[p].from || (node[G[p][i]].from_cnt>1 || node[p].from_cnt>1))) flag = true;
			if (node[G[p][i]].cnt < node[p].cnt)continue;
			que.push(G[p][i]);
			node[G[p][i]].from = p;
			node[G[p][i]].from_cnt++;
			node[G[p][i]].cnt = node[p].cnt + 1;
		}
	}
	if (flag)cout << "YES" << endl;
	else cout << "NO" << endl;

    return 0;
}

0