結果
| 問題 |
No.408 五輪ピック
|
| ユーザー |
Ymgch_K
|
| 提出日時 | 2018-01-16 21:14:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 5,000 ms |
| コード長 | 1,226 bytes |
| コンパイル時間 | 500 ms |
| コンパイル使用メモリ | 55,268 KB |
| 実行使用メモリ | 5,760 KB |
| 最終ジャッジ日時 | 2024-12-24 05:53:49 |
| 合計ジャッジ時間 | 1,802 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#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;
int s = p.step;
int prev = p.prev;
int prevprev = p.prevprev;
if (s == 5) continue;
for (auto v : g[u]) if (!used[v][s + 1]) {
if (v == prev || v == prevprev) continue;
if (s + 1 != 5 && v == 0) continue;
used[v][s + 1] = true;
q.push({v, u, prev, s + 1});
}
}
puts(used[0][5] ? "YES" : "NO");
return 0;
}
Ymgch_K