#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=1005;
bool ms[maxn][maxn];
int n, m;
vector < int > sol;
bool bio[maxn];
vector < int > put;
vector < int > tren;
vector < int > cisti;
bool dfs(int x){
bio[x]=1;
tren.clear();
vector < int > upd;
for(int i=(int)cisti.size()-1; i>-1; i--){
for(int j=0; j<cisti[i]; j++){
tren.pop_back();
}
if(!tren.empty() && ms[x][put[i]]){
if(tren.size()==1){
cisti[i]++;
upd.push_back(i);
tren.pop_back();
}
else{
tren.push_back(put[i]);
tren.push_back(x);
sol=tren;
return 1;
}
}
tren.push_back(put[i]);
}
cisti.push_back(0);
put.push_back(x);
for(int i=0; i<n; i++){
if(!bio[i] && ms[x][i]){
if(dfs(i)){
return 1;
}
}
}
while(!upd.empty()){
cisti[upd.back()]--;
upd.pop_back();
}
put.pop_back();
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
int a, b;
for(int i=0; i<m; i++){
cin >> a >> b;
a--;
b--;
ms[a][b]=1;
ms[b][a]=1;
}
for(int i=0; i<n; i++){
if(!bio[i] && dfs(i)){
for(int j=0; j<(int)sol.size(); j++){
cout << sol[j]+1 << ' ';
}
cout << '\n';
return 0;
}
}
cout << "no\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Wrong answer on graph without induced cycle |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
4 ms |
588 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
716 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
972 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1100 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
2380 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
2480 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
1484 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |