結果
| 問題 | No.408 五輪ピック |
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-10-18 18:11:43 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,023 bytes |
| 記録 | |
| コンパイル時間 | 1,443 ms |
| コンパイル使用メモリ | 142,316 KB |
| 実行使用メモリ | 30,584 KB |
| 最終ジャッジ日時 | 2024-06-12 04:34:55 |
| 合計ジャッジ時間 | 15,792 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 2 TLE * 2 -- * 8 |
ソースコード
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;
}
alias S = Tuple!(int, "index", int, "depth", int, "prev");
bool[S] D;
D[S(0, 0, -1)] = true;
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 >= 5) 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));
}
}
foreach (k, v; D) {
if (k.index == 0 && k.depth == 5) {
writeln("YES"); return;
}
}
writeln("NO");
}
izuru_matsuura