#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(!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];
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
14 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
768 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2048 KB |
Output is correct |
2 |
Correct |
7 ms |
1792 KB |
Output is correct |
3 |
Correct |
197 ms |
2168 KB |
Output is correct |
4 |
Correct |
96 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
91 ms |
1792 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
185 ms |
2040 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |