#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
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 p[mxn], r[mxn];
bool a[mxn][mxn];
vector<int> ans;
vector<int> g[mxn];
queue<int> q;
bool bfs(int x){
memset(r, -1, sizeof(r));
p[x] = -1, r[x] = x;
q.push(x);
while(!q.empty()){
int c = q.front();
q.pop();
for(int i : g[c]){
if(!~r[i]){
p[i] = c, r[i] = c == x ? i : r[c];
q.push(i);
}else if(i != p[c] && !a[r[i]][r[c]]){
for(int j = i; ~j; j = p[j]) ans.push_back(j + 1);
reverse(ans.begin(), ans.end());
for(int j = c; j != x; j = p[j]) ans.push_back(j + 1);
return 1;
}
}
}
return 0;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) a[i][i] = 1;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
u--, v--;
a[u][v] = a[v][u] = 1;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 0; i < n; i++) if(bfs(i)) break;
if(!ans.empty()){
cout << ans[0];
for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
cout << endl;
}else{
cout << "no" << endl;
}
return 0;
}
Compilation message
indcyc.cpp: In function 'int main()':
indcyc.cpp:64:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
~~^~~~~~~~~~~~
# |
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 |
0 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 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
512 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
10 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
768 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2176 KB |
Output is correct |
2 |
Correct |
6 ms |
1804 KB |
Output is correct |
3 |
Correct |
224 ms |
2176 KB |
Output is correct |
4 |
Correct |
112 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
1792 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
208 ms |
2432 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |