結果

問題 No.408 五輪ピック
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-18 18:36:30
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,806 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 148,532 KB
実行使用メモリ 18,328 KB
最終ジャッジ日時 2023-09-02 22:23:07
合計ジャッジ時間 9,429 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,740 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 57 ms
10,496 KB
testcase_06 AC 26 ms
4,488 KB
testcase_07 AC 43 ms
9,412 KB
testcase_08 AC 40 ms
7,908 KB
testcase_09 AC 38 ms
7,384 KB
testcase_10 AC 26 ms
4,512 KB
testcase_11 AC 25 ms
4,524 KB
testcase_12 AC 48 ms
8,908 KB
testcase_13 AC 55 ms
10,696 KB
testcase_14 AC 11 ms
4,368 KB
testcase_15 AC 66 ms
12,756 KB
testcase_16 AC 56 ms
9,728 KB
testcase_17 AC 56 ms
9,952 KB
testcase_18 AC 57 ms
8,496 KB
testcase_19 AC 57 ms
10,040 KB
testcase_20 AC 13 ms
4,368 KB
testcase_21 AC 8 ms
4,372 KB
testcase_22 AC 22 ms
4,548 KB
testcase_23 AC 86 ms
14,912 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
    readf("%d %d\n", &N, &M);
    alias E = Tuple!(int, int);
    bool[E] es;
    auto G = new int[][](N);
    foreach (i; 0 .. M) {
        int a, b;
        readf("%d %d\n", &a, &b);
        a--; b--;
        G[a] ~= b;
        G[b] ~= a;
        if (a > b) swap(a, b);
        es[E(a, b)] = true;
    }

    alias S = Tuple!(int, "index", int, "depth", int, "prev");
    alias P = Tuple!(int, "v", int, "prev");
    bool[S] D;
    D[S(0, 0, -1)] = true;
    P[] X;
    DList!S Q;
    Q.insert(S(0, 0, -1));
    while (!Q.empty) {
        auto c = Q.front; Q.removeFront;
        int v = c[0];
        int d = c[1];
        int prev = c[2];
        if (d == 2) {
            X ~= P(v, prev);
            continue;
        }
        foreach (nv; G[v]) {
            if (nv == prev) continue;
            int nd = d + 1;
            if (S(nv, nd, v) in D) continue;
            D[S(nv, nd, v)] = true;
            Q.insert(S(nv, nd, v));
        }
    }
    for (auto i = 0; i < X.length; i++) {
        for (auto j = i + 1; j < X.length; j++) {
            int u = X[i].v;
            int v = X[j].v;
            if (u > v) swap(u, v);
            if (E(u, v) !in es) continue;
            auto vs = [u, v, X[i].prev, X[j].prev];
            bool flag = true;
            foreach (a; 0 .. 4) {
                foreach (b; 0 .. 4) {
                    if (a == b) continue;
                    if (vs[a] == vs[b]) {
                        flag = false;
                    }
                }
            }
            if (flag) {
                writeln("YES");
                return;
            }
        }
    }
    writeln("NO");
}
0