#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
const int maxn=1005;
bool ms[maxn][maxn];
int n, m;
vector < int > sol;
bool bio[maxn];
bool dfs(int x, vector < int > minus, vector < int > put){
bio[x]=1;
vector < int > tren;
for(int i=(int)minus.size()-1; i>-1; i--){
for(int j=0; j<minus[i]; j++){
if(tren.empty()){
minus[i]=j;
break;
}
else{
tren.pop_back();
}
}
if(!tren.empty() && ms[x][put[i]]){
if(tren.size()==1){
minus[i]++;
tren.pop_back();
}
else{
tren.push_back(put[i]);
tren.push_back(x);
sol=tren;
return 1;
}
}
tren.push_back(put[i]);
}
minus.push_back(0);
put.push_back(x);
vector < int > opc;
for(int i=0; i<n; i++){
if(!bio[i] && ms[x][i]){
opc.push_back(i);
}
}
random_shuffle(opc.begin(), opc.end());
for(int i=0; i<(int)opc.size(); i++){
if(!bio[opc[i]] && dfs(opc[i], minus, put)){
return 1;
}
}
return 0;
}
int main(){
srand(time(NULL));
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;
}
vector < int > red;
for(int i=0; i<n; i++){
red.push_back(i);
}
for(int k=0; k<10; k++){
memset(bio, 0, sizeof(bio));
random_shuffle(red.begin(), red.end());
for(int i=0; i<n; i++){
if(!bio[red[i]] && dfs(red[i], {}, {})){
for(int j=0; j<(int)sol.size(); j++){
cout << sol[j]+1 << ' ';
}
cout << '\n';
return 0;
}
}
}
cout << "no\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1228 KB |
Output is correct |
2 |
Incorrect |
2 ms |
972 KB |
Wrong adjacency |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
716 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
9368 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
76 ms |
1856 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
2980 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |