#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;
}
if (a1 == a2) {
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 |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
332 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
391 ms |
412 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
13 ms |
484 KB |
Output is correct |
4 |
Correct |
601 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
190 ms |
464 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
1376 KB |
Output is correct |
2 |
Correct |
116 ms |
808 KB |
Output is correct |
3 |
Execution timed out |
1084 ms |
1424 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
6340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |