結果
問題 |
No.408 五輪ピック
|
ユーザー |
|
提出日時 | 2016-08-06 00:19:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,270 bytes |
コンパイル時間 | 992 ms |
コンパイル使用メモリ | 88,992 KB |
実行使用メモリ | 13,952 KB |
最終ジャッジ日時 | 2024-11-07 00:18:19 |
合計ジャッジ時間 | 8,470 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 8 TLE * 1 -- * 6 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <set> using namespace std; vector<vector<int>> connect_v; vector<set<int>> connect_s; template <class T> void show(T t) { for (auto e : t) { cout << e << " "; } cout << endl; } bool dfs(vector<int> &v, int n_points) { int now, idx; switch (n_points) { case 1: now = v[2]; idx = 1; break; case 2: now = v[2]; idx = 3; break; case 3: now = v[1]; idx = 0; break; case 4: now = v[3]; idx = 4; break; case 5: return connect_s[v[4]].count(0) > 0; default:return false; } for (auto next : connect_v[now]) { if (find(v.begin(), v.end(), next) != v.end()) { continue; } v[idx] = next; if (dfs(v, n_points + 1)) { return true; } v[idx] = -1; } return false; } int main() { int n, m, a, b; scanf("%d %d", &n, &m); connect_v.assign(n, vector<int>()); connect_s.assign(n, set<int>()); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); a--; b--; connect_v[a].emplace_back(b); connect_v[b].emplace_back(a); connect_s[a].insert(b); connect_s[b].insert(a); } vector<int> points(5, -1); points[2] = 0; bool ret = dfs(points, 1); if (ret) { printf("YES\n"); } else { printf("NO\n"); } return 0; }