結果

問題 No.408 五輪ピック
ユーザー femto
提出日時 2016-08-05 23:49:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 393 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 88,952 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2024-11-07 04:46:51
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <set>
using namespace std;
template<typename T> void setmin(T& a, T& b) { a = min(a, b); }
template<typename T> void setmax(T& a, T& b) { a = max(a, b); }

typedef pair<int, int> P;

int N, M;

vector<int> G[20001];
set<int> par[20001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	set<int> two;
	for(int c : G[1]) {
		for(int cc : G[c]) {
			if(cc == 1) continue;
			par[cc].insert(c);
			two.insert(cc);
		}
	}

	for(int cc : two) {
		for(int ccc : G[cc]) {
			for(int p : par[cc]) {
				if(p == ccc) continue;
				if(two.find(ccc) == two.end()) continue;
				int rem = par[ccc].size();
				if(par[ccc].find(p) != par[ccc].end()) rem--;
				if(par[ccc].find(cc) != par[ccc].end()) rem--;
				if(rem > 0) {
					cout << "YES" << endl;
					return 0;
				}
			}
		}
	}
	cout << "NO" << endl;
}
0