結果
| 問題 | No.408 五輪ピック |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-06 00:08:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,250 bytes |
| 記録 | |
| コンパイル時間 | 1,246 ms |
| コンパイル使用メモリ | 88,936 KB |
| 実行使用メモリ | 15,392 KB |
| 最終ジャッジ日時 | 2024-11-07 00:08:53 |
| 合計ジャッジ時間 | 8,953 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 TLE * 1 -- * 4 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
const int INF = 99;
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;
}
// v[0, b, c, d, e]
bool dfs(vector<int> &v, int idx) {
// printf("%d: ", idx);
// show(v);
int now = v[idx];
if (idx == 4) {
return connect_s[now].count(0) > 0;
}
for (auto next : connect_v[now]) {
if (find(v.begin(), v.end(), next) != v.end()) {
continue;
}
v[idx + 1] = next;
if (dfs(v, idx + 1)) {
return true;
}
v[idx + 1] = -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);
}
// for (int i = 0; i < 5; i++) {
// printf("%d: ", i);
// show(connect_s[i]);
// }
vector<int> points(5, -1);
points[0] = 0;
bool ret = dfs(points, 0);
if (ret) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}