結果

問題 No.408 五輪ピック
ユーザー kapokapo
提出日時 2016-08-09 13:45:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,842 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 88,440 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-24 22:58:42
合計ジャッジ時間 2,267 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,760 KB
testcase_01 AC 4 ms
5,632 KB
testcase_02 AC 4 ms
5,888 KB
testcase_03 AC 3 ms
5,760 KB
testcase_04 AC 3 ms
5,888 KB
testcase_05 AC 14 ms
6,784 KB
testcase_06 AC 12 ms
6,656 KB
testcase_07 AC 16 ms
6,784 KB
testcase_08 AC 13 ms
6,528 KB
testcase_09 AC 13 ms
6,656 KB
testcase_10 AC 12 ms
6,528 KB
testcase_11 AC 11 ms
6,528 KB
testcase_12 AC 18 ms
6,912 KB
testcase_13 AC 15 ms
6,912 KB
testcase_14 AC 6 ms
6,400 KB
testcase_15 AC 14 ms
7,296 KB
testcase_16 AC 16 ms
6,912 KB
testcase_17 AC 17 ms
6,912 KB
testcase_18 AC 19 ms
6,912 KB
testcase_19 AC 18 ms
7,296 KB
testcase_20 AC 8 ms
6,400 KB
testcase_21 AC 6 ms
6,144 KB
testcase_22 AC 11 ms
6,528 KB
testcase_23 AC 25 ms
7,680 KB
testcase_24 AC 20 ms
7,552 KB
testcase_25 AC 15 ms
7,296 KB
testcase_26 AC 21 ms
7,296 KB
testcase_27 AC 14 ms
7,168 KB
testcase_28 AC 12 ms
6,528 KB
testcase_29 AC 12 ms
6,656 KB
testcase_30 AC 4 ms
5,760 KB
testcase_31 AC 4 ms
5,632 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |                 scanf("%d %d", &V1[i], &V2[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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