結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 22:04:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,240 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 175,648 KB
実行使用メモリ 9,308 KB
最終ジャッジ日時 2023-08-14 14:50:16
合計ジャッジ時間 10,212 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 26 ms
6,056 KB
testcase_06 AC 32 ms
4,556 KB
testcase_07 AC 67 ms
5,076 KB
testcase_08 AC 19 ms
5,104 KB
testcase_09 AC 22 ms
5,036 KB
testcase_10 AC 23 ms
4,624 KB
testcase_11 AC 43 ms
4,468 KB
testcase_12 AC 96 ms
5,476 KB
testcase_13 AC 25 ms
5,760 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 27 ms
5,848 KB
testcase_16 AC 27 ms
5,756 KB
testcase_17 AC 27 ms
5,884 KB
testcase_18 AC 31 ms
5,876 KB
testcase_19 AC 59 ms
5,772 KB
testcase_20 AC 10 ms
4,384 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 16 ms
4,428 KB
testcase_23 AC 31 ms
5,848 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
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 : a < e.a;
    }
};

int main() {
    int N, M;
    scanf("%d %d\n", &N, &M);
    set<Edge> es;
    vector<Edge> es1;
    vector<int> zero_n;
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d\n", &a, &b);
        a--; b--;
        if (a > b) swap(a, b);
        if (a == 0) zero_n.push_back(b);
        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) {
        bool a = false, b = false;
        int c = 0;
        for (auto i : zero_n) {
            if (i == e.a || i == e.b) continue;
            bool flag = false;
            if (f(e.a, i)) {
                a = true;
                flag =true;
            }
            if (f(e.b, i)) {
                b = true;
                flag = true;
            }
            c += flag;
        }
        if (c >= 2 && a && b) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

}
0