結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 23:26:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,699 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 178,972 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-08-14 14:56:30
合計ジャッジ時間 11,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 39 ms
6,368 KB
testcase_06 AC 16 ms
5,644 KB
testcase_07 AC 23 ms
5,856 KB
testcase_08 AC 19 ms
5,548 KB
testcase_09 AC 19 ms
5,564 KB
testcase_10 AC 16 ms
5,244 KB
testcase_11 AC 16 ms
5,092 KB
testcase_12 AC 26 ms
6,040 KB
testcase_13 AC 31 ms
6,324 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 55 ms
6,424 KB
testcase_16 AC 33 ms
6,484 KB
testcase_17 AC 30 ms
6,600 KB
testcase_18 AC 29 ms
6,696 KB
testcase_19 AC 30 ms
6,640 KB
testcase_20 AC 8 ms
4,384 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 12 ms
4,996 KB
testcase_23 AC 29 ms
6,884 KB
testcase_24 AC 645 ms
5,684 KB
testcase_25 AC 1,444 ms
6,524 KB
testcase_26 AC 36 ms
6,956 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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) ^ (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;
            }
        }
        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