結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2016-10-18 18:35:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 620 ms / 5,000 ms |
コード長 | 1,120 bytes |
コンパイル時間 | 916 ms |
コンパイル使用メモリ | 72,044 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-22 12:34:26 |
合計ジャッジ時間 | 3,572 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include <iostream> #include<algorithm> #include <vector> #include <queue> using namespace std; int N, M; struct Node { int cnt=INT32_MAX; int from; int from_cnt = 0; }; int main() { cin >> N >> M; vector<vector<int> > G(N+1); vector<Node> node(N + 1); node[1].cnt = 0; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } queue<int> que; for (int i = 0; i < G[1].size(); i++) { que.push(G[1][i]); node[G[1][i]].from = 1; node[G[1][i]].from_cnt++; node[G[1][i]].cnt = node[1].cnt + 1; } bool flag = false; while (!que.empty()) { int p = que.front(); que.pop(); for (int i = 0; i < G[p].size(); i++) { if (node[p].cnt == 3)continue; if (node[G[p][i]].cnt == 2 && node[p].cnt == 2 && (node[G[p][i]].from!=node[p].from || (node[G[p][i]].from_cnt>1 || node[p].from_cnt>1))) flag = true; if (node[G[p][i]].cnt < node[p].cnt)continue; que.push(G[p][i]); node[G[p][i]].from = p; node[G[p][i]].from_cnt++; node[G[p][i]].cnt = node[p].cnt + 1; } } if (flag)cout << "YES" << endl; else cout << "NO" << endl; return 0; }