結果

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

テストケース

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

ソースコード

diff #

#include <cstdio>
#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 == prev || v == prevprev) continue;
                        used[v][s + 1] = true;
                        q.push({v, u, prev, s + 1});
                }
        }
        puts(used[0][5] ? "YES" : "NO");
        return 0;
}

0