結果

問題 No.408 五輪ピック
ユーザー kapokapo
提出日時 2016-08-09 13:45:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,842 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 88,564 KB
実行使用メモリ 7,724 KB
最終ジャッジ日時 2023-08-07 04:43:50
合計ジャッジ時間 2,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,872 KB
testcase_01 AC 4 ms
5,900 KB
testcase_02 AC 3 ms
5,896 KB
testcase_03 AC 3 ms
5,856 KB
testcase_04 AC 4 ms
5,856 KB
testcase_05 AC 14 ms
6,852 KB
testcase_06 AC 11 ms
6,908 KB
testcase_07 AC 14 ms
6,912 KB
testcase_08 AC 12 ms
6,664 KB
testcase_09 AC 13 ms
6,800 KB
testcase_10 AC 11 ms
6,688 KB
testcase_11 AC 10 ms
6,424 KB
testcase_12 AC 16 ms
6,896 KB
testcase_13 AC 14 ms
7,176 KB
testcase_14 AC 6 ms
6,104 KB
testcase_15 AC 13 ms
7,004 KB
testcase_16 AC 15 ms
6,844 KB
testcase_17 AC 16 ms
6,932 KB
testcase_18 AC 17 ms
6,936 KB
testcase_19 AC 18 ms
7,004 KB
testcase_20 AC 7 ms
6,240 KB
testcase_21 AC 6 ms
6,248 KB
testcase_22 AC 10 ms
6,616 KB
testcase_23 AC 23 ms
7,724 KB
testcase_24 AC 18 ms
7,292 KB
testcase_25 AC 13 ms
7,220 KB
testcase_26 AC 20 ms
7,216 KB
testcase_27 AC 14 ms
7,364 KB
testcase_28 AC 11 ms
6,448 KB
testcase_29 AC 12 ms
6,588 KB
testcase_30 AC 3 ms
5,840 KB
testcase_31 AC 3 ms
5,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int N, M;
int V1[50001];
int V2[50001];
Vi A[50001];
Vi B[50001];

int main()
{
	cin >> N >> M;
	rep(i,0,M) {
		scanf("%d %d", &V1[i], &V2[i]);
		V1[i]--; V2[i]--;
		A[V2[i]].pb(V1[i]);
		A[V1[i]].pb(V2[i]);
	}

	for (auto a: A[0]) {
		for (auto b: A[a]) {
			if (b) B[b].pb(a);
		}
	}

	rep(i, 0, M) {
		int l = V1[i];
		int r = V2[i];
		if (B[l].size() && B[r].size()) {
			//printf("l=%d r=%d len(B[l])=%d len(B[r])=%d\n",l,r,len(B[l]),len(B[r]));
			if (B[l].size() == 1 && B[r].size() == 1) {
				if (B[l][0] != B[r][0] && B[l][0] != r && B[r][0] != l) {
					cout << "YES" << endl;
					return 0;
				}
			}
			else if (B[l].size() >= 1 && B[r].size() >= 1 && max(B[l].size(), B[r].size()) >= 2) {
				if (B[l].size() >= 2 && B[r].size() == 1) {
					auto it = find(all(B[l]), r);
					if (it != B[l].end()) continue;
				}
				if (B[r].size() >= 2 && B[l].size() == 1) {
					auto it = find(all(B[r]), l);
					if (it != B[r].end()) continue;
				}
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0