結果

問題 No.408 五輪ピック
ユーザー Ymgch_KYmgch_K
提出日時 2018-01-16 21:25:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,118 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 58,040 KB
実行使用メモリ 5,824 KB
最終ジャッジ日時 2023-08-25 19:52:51
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 11 ms
4,968 KB
testcase_07 AC 14 ms
4,700 KB
testcase_08 AC 10 ms
4,376 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 16 ms
4,872 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 13 ms
4,380 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 17 ms
4,388 KB
testcase_19 AC 19 ms
4,940 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 10 ms
4,964 KB
testcase_23 AC 27 ms
5,824 KB
testcase_24 WA -
testcase_25 AC 11 ms
4,384 KB
testcase_26 AC 20 ms
5,676 KB
testcase_27 AC 11 ms
4,376 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 11 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

struct state { int node, prev, prevprev, step; };

int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        vector<vector<int>> g(n);
        for (int i = 0; i < m; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<vector<bool>> used(n, vector<bool> (6));
        queue<state> q;
        q.push({ 0, -1, -1, 0 });
        used[0][0] = true;
        while (!q.empty()) {
                state p = q.front(); q.pop();
                int u = p.node, s = p.step, prev = p.prev, prevprev = p.prevprev;
                if (s == 5) continue;
                for (auto v : g[u]) if (!used[v][s + 1]) {
                        if ((s + 1 != 5 && v == 0) || v == prevprev) continue;
                        used[v][s + 1] = true;
                        q.push({v, u, prev, s + 1});
                }
        }
        puts(used[0][5] ? "YES" : "NO");
        return 0;
}
0