結果

問題 No.408 五輪ピック
コンテスト
ユーザー Ymgch_K
提出日時 2018-01-16 21:04:35
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,049 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 771 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-30 02:35:42
合計ジャッジ時間 3,446 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

struct state { int node, 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, 0 });
        used[0][0] = true;
        while (!q.empty()) {
                state p = q.front(); q.pop();
                int u = p.node;
                int s = p.step;
                if (s == 5) continue;
                for (auto v : g[u]) if (!used[v][s + 1]) {
                        if (s + 1 != 5 && v == 0) continue;
                        used[v][s + 1] = true;
                        q.push({v, s + 1});
                }
        }
        puts(used[0][5] ? "YES" : "NO");
        return 0;
}

0