結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 23:31:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 490 ms / 5,000 ms
コード長 1,732 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 179,740 KB
実行使用メモリ 7,160 KB
最終ジャッジ日時 2023-08-14 14:56:38
合計ジャッジ時間 4,537 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 22 ms
6,368 KB
testcase_06 AC 15 ms
5,452 KB
testcase_07 AC 22 ms
5,968 KB
testcase_08 AC 17 ms
5,496 KB
testcase_09 AC 18 ms
5,580 KB
testcase_10 AC 15 ms
5,220 KB
testcase_11 AC 15 ms
5,124 KB
testcase_12 AC 25 ms
6,076 KB
testcase_13 AC 23 ms
6,316 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 22 ms
6,640 KB
testcase_16 AC 24 ms
6,324 KB
testcase_17 AC 25 ms
6,624 KB
testcase_18 AC 27 ms
6,720 KB
testcase_19 AC 29 ms
6,980 KB
testcase_20 AC 8 ms
4,504 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 12 ms
5,248 KB
testcase_23 AC 29 ms
6,936 KB
testcase_24 AC 19 ms
5,764 KB
testcase_25 AC 57 ms
6,488 KB
testcase_26 AC 33 ms
7,160 KB
testcase_27 AC 490 ms
6,380 KB
testcase_28 AC 37 ms
5,280 KB
testcase_29 AC 82 ms
5,116 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 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;
    }
};
namespace std {
    template<> struct hash<Edge> {
        size_t operator()(const Edge& e) const {
            return size_t((e.a << 15) ^ e.b);
        }
    };
}

const int INF = 1<<28;

int main() {
    int N, M;
    scanf("%d %d\n", &N, &M);
    unordered_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;
            }
        }
        if (a < 0) continue;
        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