結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 22:58:26
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,537 ms / 5,000 ms
コード長 1,443 bytes
コンパイル時間 1,216 ms
コンパイル使用メモリ 79,748 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-09-02 22:25:49
合計ジャッジ時間 6,208 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 50 ms
8,040 KB
testcase_06 AC 24 ms
4,580 KB
testcase_07 AC 39 ms
7,456 KB
testcase_08 AC 36 ms
7,424 KB
testcase_09 AC 35 ms
7,416 KB
testcase_10 AC 27 ms
4,616 KB
testcase_11 AC 25 ms
4,412 KB
testcase_12 AC 47 ms
7,716 KB
testcase_13 AC 48 ms
9,252 KB
testcase_14 AC 10 ms
4,372 KB
testcase_15 AC 51 ms
7,712 KB
testcase_16 AC 51 ms
8,008 KB
testcase_17 AC 50 ms
8,972 KB
testcase_18 AC 53 ms
8,324 KB
testcase_19 AC 53 ms
10,016 KB
testcase_20 AC 13 ms
4,372 KB
testcase_21 AC 8 ms
4,368 KB
testcase_22 AC 21 ms
6,124 KB
testcase_23 AC 49 ms
7,448 KB
testcase_24 AC 34 ms
8,372 KB
testcase_25 AC 244 ms
7,732 KB
testcase_26 AC 58 ms
8,268 KB
testcase_27 AC 886 ms
7,780 KB
testcase_28 AC 476 ms
6,944 KB
testcase_29 AC 1,537 ms
8,204 KB
testcase_30 AC 2 ms
4,372 KB
testcase_31 AC 1 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.algorithm;
import std.typecons;
import std.string;
import std.array;
import std.conv;
import std.container;

void main() {
    int N, M;
    scanf("%d %d\n", &N, &M);
    alias E = Tuple!(int, int);
    bool[E] es;
    E[] es1;
    auto zero_n = new bool[N];
    auto G = new int[][](N);
    foreach (i; 0 .. M) {
        int a, b;
        scanf("%d %d\n", &a, &b);
        a--; b--;
        G[a] ~= b;
        G[b] ~= a;
        if (a > b) swap(a, b);
        if (a == 0) zero_n[b] = true;
        else es1 ~= E(a, b);
        es[E(a, b)] = true;
    }

    bool f(int a, int b) {
        if (a > b) swap(a, b);
        return E(a, b) in es ? true : false;
    }

    const int INF = int.max / 2;

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

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

}
0