結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 23:14:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,535 bytes
コンパイル時間 4,881 ms
コンパイル使用メモリ 178,172 KB
実行使用メモリ 7,436 KB
最終ジャッジ日時 2023-08-14 14:54:20
合計ジャッジ時間 13,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 29 ms
6,308 KB
testcase_06 AC 17 ms
5,560 KB
testcase_07 AC 27 ms
6,156 KB
testcase_08 AC 21 ms
5,852 KB
testcase_09 AC 22 ms
5,820 KB
testcase_10 AC 18 ms
5,200 KB
testcase_11 AC 18 ms
4,936 KB
testcase_12 AC 32 ms
6,468 KB
testcase_13 AC 29 ms
6,344 KB
testcase_14 AC 7 ms
4,384 KB
testcase_15 AC 29 ms
6,464 KB
testcase_16 AC 32 ms
6,760 KB
testcase_17 AC 32 ms
6,660 KB
testcase_18 AC 34 ms
6,956 KB
testcase_19 AC 37 ms
7,120 KB
testcase_20 AC 9 ms
4,416 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 16 ms
5,116 KB
testcase_23 AC 37 ms
7,088 KB
testcase_24 AC 26 ms
6,124 KB
testcase_25 AC 405 ms
6,460 KB
testcase_26 AC 49 ms
7,436 KB
testcase_27 AC 1,417 ms
6,432 KB
testcase_28 AC 1,735 ms
5,436 KB
testcase_29 TLE -
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Edge {
    int a, b;
    Edge(int a, int b) : a(a), b(b) {}
    bool operator<(const Edge& e) const {
        return a == e.a ? b < e.b : a < e.a;
    }
};

const int INF = 1<<28;

int main() {
    int N, M;
    scanf("%d %d\n", &N, &M);
    set<Edge> es;
    vector<Edge> es1;
    vector<vector<int>> G(N);
    vector<bool> zero_n(N, false);
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d\n", &a, &b);
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
        if (a > b) swap(a, b);
        if (a == 0) zero_n[b] = true;
        else es1.emplace_back(a, b);
        es.emplace(a, b);
    }

    auto f = [&](int a, int b) {
        if (a > b) swap(a, b);
        return es.count(Edge(a, b));
    };

    for (auto e : es1) {
        int a = -1, b = -1;
        int c = 0;
        for (auto i : G[e.a]) {
            if (!zero_n[i]) continue;
            if (i == e.b) continue;
            if (f(e.a, i)) {
                if (a < 0) a = i;
                else a = INF;
            }
        }
        for (auto i : G[e.b]) {
            if (!zero_n[i]) continue;
            if (i == e.a) continue;
            if (f(e.b, i)) {
                if (b < 0) b = i;
                else b = INF;
            }
        }

        if (a >= 0 && b >= 0) {
            if ( (a == INF || b == INF) || (a != b) ) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;

}
0