#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> AdjMatrix;
vector<int> component;
int numNodes, numEdges, N, R;
void outputCompt(int node, int prev, int start){
cout << node+1 << " ";
for(int other: component){
if(other == node) continue;
if(other == start) continue;
if(other == prev) continue;
if(AdjMatrix[node][other] == 0) {
//cout << node << "-> " << other << endl;
outputCompt(other, node, start);
return;
}
}
}
int main(){
int a, b;
cin >> N >> R;
AdjMatrix = vector<vector<int>> (N, vector<int>(N, 1));
int sol = -1;
int first = -1;
for(int i = 0; i < R; ++i){
cin >> a >> b;
a--; b--;
AdjMatrix[a][b] = AdjMatrix[b][a] = 0;
}
for(int mask = 1; (mask < (1 << N)) and (sol == -1); ++mask){
numEdges = 0;
numNodes = __builtin_popcount(mask);
if(numNodes > 3){
bool possible = true;
for(int i = 0; i < N; ++i){
if(mask & (1 << i)){
int cnt = 0;
for(int j = 0; j < N; ++j){
if(i == j) continue;
//cout << mask << " " << i <<" " << j << endl;
if(mask & (1 << j))cnt+= AdjMatrix[i][j];
}
if(cnt != numNodes-3) possible = false;
}
}
if(possible) sol = mask;
}
}
if(sol == -1) cout << sol << endl;
else{
//cout << sol << endl;
for(int i = 0; i < N; ++i){
if(sol & (1 << i)) {
component.push_back(i);
//cout << i << endl;
first = i;
}
}
outputCompt(first, -1, first);
cout << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Wrong answer on graph without induced cycle |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
300 KB |
Wrong answer on graph without induced cycle |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Integer -1 violates the range [1, 100] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Integer -1 violates the range [1, 100] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
596 KB |
Wrong answer on graph without induced cycle |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
664 KB |
Integer -1 violates the range [1, 300] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
4600 KB |
Integer -1 violates the range [1, 1000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
4308 KB |
Integer -1 violates the range [1, 1000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
1688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |