結果

問題 No.408 五輪ピック
ユーザー h_nosonh_noson
提出日時 2016-09-15 21:39:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 1,404 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 91,992 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-28 13:53:38
合計ジャッジ時間 2,169 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 23 ms
6,272 KB
testcase_06 AC 10 ms
5,760 KB
testcase_07 AC 13 ms
5,888 KB
testcase_08 AC 11 ms
5,504 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 9 ms
5,504 KB
testcase_11 AC 8 ms
5,504 KB
testcase_12 AC 14 ms
5,760 KB
testcase_13 AC 20 ms
5,888 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 46 ms
7,424 KB
testcase_16 AC 17 ms
5,632 KB
testcase_17 AC 15 ms
5,760 KB
testcase_18 AC 15 ms
5,760 KB
testcase_19 AC 16 ms
5,760 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 8 ms
5,504 KB
testcase_23 AC 44 ms
8,704 KB
testcase_24 AC 18 ms
6,912 KB
testcase_25 AC 36 ms
7,808 KB
testcase_26 AC 18 ms
6,272 KB
testcase_27 AC 42 ms
7,808 KB
testcase_28 AC 25 ms
6,400 KB
testcase_29 AC 26 ms
6,656 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

vector<int> e[20000];
set<int> s[20000];

int main(void) {
    int i, n, m;
    scanf("%d%d",&n,&m);
    REP (i,m) {
        int a, b;
        scanf("%d%d",&a,&b);
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    for (auto x: e[0]) for (auto y: e[x]) if (y != 0) {
        s[y].insert(x);
    }
    bool ans = false;
    REP (i,n) for (auto x: e[i]) if (x != 0) {
        bool bi = s[i].count(x), bx = s[x].count(i);
        if (bi) s[i].erase(x);
        if (bx) s[x].erase(i);
        int ni = s[i].size(), nx = s[x].size();
        if (ni == 1 && nx == 1 && *s[i].begin() != *s[x].begin()) ans = true;
        else if ((ni > 1 && nx > 0) || (ni > 0 && nx > 1)) ans = true;
        if (bi) s[i].insert(x);
        if (bx) s[x].insert(i);
    }
    if (ans)
        puts("YES");
    else
        puts("NO");
    return 0;
}
0