/**
* author: Haunted_Cpp
**/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
const int MAX_N = 1e3 + 5;
vector<vector<int>> g(MAX_N);
bool vis[MAX_N];
deque<int> stk;
int source;
bool solve(int node) {
//~ debug(node);
vis[node] = true;
stk.push_back(node);
bool res = false;
for (auto to : g[node]) {
if (to == source) {
// CHECK
vector<int> cycle;
for (auto cur : stk) {
cycle.emplace_back(cur);
}
//~ cout << "YES" << '\n';
//~ debug(cycle);
if ((int)cycle.size() < 4) {
continue;
}
bool work = true;
for (auto current : cycle) {
int cnt = 0;
//~ debug(current);
for (auto nxt : cycle) {
//~ debug(nxt);
//~ debug(find(g[current].begin(), g[current].end(), nxt) != g[current].end());
cnt += (find(g[current].begin(), g[current].end(), nxt) != g[current].end());
}
work &= (cnt == 2);
//~ debug(cnt);
}
res |= work;
if (work) {
for(auto ans : cycle) {
cout << ans + 1 << ' ';
}
cout << '\n';
return true;
}
continue;
}
if (!vis[to]) {
vis[to] = true;
res |= solve(to);
}
}
stk.pop_back();
vis[node] = false;
return res;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int st, et;
cin >> st >> et;
--st; --et;
g[st].emplace_back(et);
g[et].emplace_back(st);
}
//~ source = 1;
//~ solve(1);
for (int i = 0; i < n; i++) {
source = i;
if(solve(i)) {
memset(vis, false, sizeof(vis));
return 0;
}
}
cout << "no" << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
384 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1074 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
1400 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1082 ms |
768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1096 ms |
2148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |