結果

問題 No.408 五輪ピック
ユーザー izuru_matsuura
提出日時 2016-10-18 18:04:02
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 139,392 KB
実行使用メモリ 6,976 KB
最終ジャッジ日時 2024-06-12 04:34:05
合計ジャッジ時間 3,918 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
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);
    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;
    }

    auto D = new bool[][](N, 6);
    foreach (i; 0 .. N) D[i][] = false;
    D[0][0] = true;
    alias S = Tuple!(int, int);
    DList!S Q;
    Q.insert(S(0, 0));
    while (!Q.empty) {
        auto c = Q.front; Q.removeFront;
        int v = c[0];
        int d = c[1];
        D[v][d] = true;
        if (d >= 5) continue;
        foreach (nv; G[v]) {
            int nd = d + 1;
            if (D[nv][nd]) continue;
            D[nv][nd] = true;
            Q.insert(S(nv, nd));
        }
    }
    writeln(D[0][5] ? "YES" : "NO");
}
0