#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)
template<class T>
inline bool mxto(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T>
inline bool mnto(T &a, T b) {return a > b ? a = b, 1 : 0;}
typedef long long ll;
#define FI first
#define SE second
#define MP make_pair
typedef pair<int, int> ii;
#define pb push_back
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<ii> vii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
#define MAXN 1005
#define INF 1000000005
#define LINF 1000000000000000005ll
int n, r;
vi adj[MAXN];
int vis[MAXN], dist[MAXN], p[MAXN];
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n >> r;
REP (i, 0, r) {
int a, b; cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
REP (i, 1, n + 1) {
set<ii> ban;
queue<int> bfs;
vis[i] = i;
dist[i] = 0;
bfs.push(i);
cerr << i << '\n';
while (!bfs.empty()) {
int u = bfs.front(); bfs.pop();
cerr << ' ' << u << '\n';
for (int v : adj[u]) {
cerr << " " << v << '\n';
if (vis[v] == i) {
if (v == p[u]) continue;
if (dist[u] == 1 && dist[v] == 1) {
ban.insert(MP(min(u, v), max(u, v)));
continue;
}
assert(dist[u] + dist[v] + 1 > 3);
vi ans;
int x = v;
int a1 = -1;
while (x != i) {
a1 = x;
ans.pb(x);
x = p[x];
}
ans.pb(i);
reverse(ALL(ans));
x = u;
int a2 = -1;
while (x != i) {
a2 = x;
ans.pb(x);
x = p[x];
}
if (ban.find(MP(min(a1, a2), max(a1, a2))) != ban.end()) {
continue;
}
for (int a : ans) {
cout << a << ' ';
}
cout << '\n';
return 0;
}
vis[v] = i;
dist[v] = dist[u] + 1;
p[v] = u;
bfs.push(v);
}
}
}
cout << "no\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Wrong answer on graph without induced cycle |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
332 KB |
Wrong answer on graph without induced cycle |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
380 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1316 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
716 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
6352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |