#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <set>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mxn = 1000;
int n, m;
int d[mxn], p[mxn];
vector<int> g[mxn];
set<int, greater<int>> s;
void dfs(int c){
bool t = 0;
for(int i : g[c]) t |= (~d[i] && d[c] - d[i] == 2);
if(t){
s.insert(d[c] - 2);
}else{
int x = -1;
for(int i : g[c]) if(i != p[c] && ~d[i] && (!~x || d[i] > d[x])) x = i;
if(~x && (s.empty() || d[x] > *s.begin())){
cout << c + 1;
for(int i = p[c]; ~i && d[i] >= d[x]; i = p[i]) cout << " " << i + 1;
cout << endl;
exit(0);
}
}
for(int i : g[c]){
if(~d[i]) continue;
d[i] = d[c] + 1, p[i] = c;
dfs(i);
}
if(t) s.erase(d[c] - 2);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 0; i < n; i++){
memset(d, -1, sizeof(d));
d[i] = 0, p[i] = -1;
dfs(i);
}
cout << "no" << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
504 KB |
Output is correct |
2 |
Incorrect |
22 ms |
504 KB |
Expected integer, but "no" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
512 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
416 ms |
1044 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
268 ms |
684 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1408 KB |
Output is correct |
2 |
Correct |
207 ms |
1400 KB |
Output is correct |
3 |
Incorrect |
468 ms |
1272 KB |
Expected integer, but "no" found |
4 |
Halted |
0 ms |
0 KB |
- |