#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 7;
const int INF = (int) 1e9 + 7;
int n, m, dist[N], par[N];
vector<int> g[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
///freopen ("input.txt", "r", stdin);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
sort(g[i].begin(), g[i].end());
}
for (int root = 1; root <= n; root++) {
for (auto &v1 : g[root]) {
for (auto &v2 : g[root]) {
if (v1 == v2) continue;
for (int i = 1; i <= n; i++) {
dist[i] = INF;
par[i] = 0;
}
dist[root] = -1;
for (auto &v : g[root]) {
if (v != v1 && v != v2) {
dist[v] = -1;
}
}
queue<int> q;
dist[v1] = 0;
q.push(v1);
while (!q.empty()) {
int a = q.front();
q.pop();
for (auto &b : g[a]) {
if (dist[b] == INF) {
dist[b] = 1 + dist[a];
par[b] = a;
q.push(b);
}
}
}
if (dist[v2] == 1) continue;
if (dist[v2] != -1 && dist[v2] != INF) {
while (v2 != v1) {
cout << v2 << " ";
v2 = par[v2];
}
cout << v1 << " " << root << "\n";
exit(0);
}
}
}
}
cout << "no\n";
exit(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
67 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
736 ms |
392 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
69 ms |
468 KB |
Output is correct |
4 |
Execution timed out |
1082 ms |
468 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
340 KB |
Output is correct |
2 |
Correct |
774 ms |
404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
543 ms |
616 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
724 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1084 ms |
1360 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |