結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 22:55:05
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2,806 ms / 5,000 ms
コード長 1,438 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 79,696 KB
実行使用メモリ 10,700 KB
最終ジャッジ日時 2023-09-02 22:25:16
合計ジャッジ時間 8,706 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 49 ms
9,752 KB
testcase_06 AC 27 ms
5,820 KB
testcase_07 AC 44 ms
7,208 KB
testcase_08 AC 36 ms
8,976 KB
testcase_09 AC 34 ms
7,188 KB
testcase_10 AC 32 ms
6,212 KB
testcase_11 AC 28 ms
5,928 KB
testcase_12 AC 56 ms
10,028 KB
testcase_13 AC 47 ms
9,524 KB
testcase_14 AC 11 ms
4,368 KB
testcase_15 AC 50 ms
8,248 KB
testcase_16 AC 51 ms
8,796 KB
testcase_17 AC 52 ms
10,700 KB
testcase_18 AC 54 ms
8,932 KB
testcase_19 AC 57 ms
9,980 KB
testcase_20 AC 13 ms
4,372 KB
testcase_21 AC 7 ms
4,368 KB
testcase_22 AC 23 ms
4,368 KB
testcase_23 AC 54 ms
9,500 KB
testcase_24 AC 41 ms
8,964 KB
testcase_25 AC 390 ms
8,664 KB
testcase_26 AC 67 ms
8,704 KB
testcase_27 AC 1,552 ms
10,288 KB
testcase_28 AC 800 ms
8,192 KB
testcase_29 AC 2,806 ms
8,448 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 1 ms
4,372 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;
    bool[int] zero_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 (i !in zero_n) 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 (i !in zero_n) 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