結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2018-01-16 21:30:17 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 29 ms / 5,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 52,096 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-12-24 05:54:01 |
合計ジャッジ時間 | 1,990 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d%d", &a, &b); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#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; }