#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e4 + 10;
const int mod = 1e6 + 7;
vector <int> g[maxn];
int n;
bool visited[maxn];
void dfs (int v, int mask, bool print = 0) {
visited[v] = 1;
for (auto u : g[v])
if (mask & (1 << u) and !visited[u])
dfs (u, mask, print);
if (print)
cout << v + 1 << " ";
}
bool check (int mask) {
memset (visited, 0, sizeof visited);
for (int v = 0; v < n; v++) {
int cnt = 0;
for (auto u : g[v]) {
if (mask & (1 << u))
cnt ++;
}
if (cnt != 2)
return 0;
}
int cnt = 0;
for (int v = 0; v < n; v++) {
if (!visited[v] and mask & (1 << v)) {
dfs (v, mask);
cnt ++;
}
}
return cnt == 1;
}
int bitmask (int mask) {
int ret = 0;
while (mask) {
ret ++;
mask -= mask & -mask;
}
return ret;
}
int main() {
int m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int v, u;
cin >> v >> u;
v --, u --;
g[v].PB (u);
g[u].PB (v);
}
for (int mask = 0; mask < (1 << n); mask++) {
if (bitmask (mask) > 3 and check (mask)) {
memset (visited, 0, sizeof visited);
for (int v = 0; v < n; v++)
if (!visited[v] and mask & (1 << v))
dfs (v, mask, 1);
return 0;
}
}
cout << "no" << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
784 KB |
Output is correct |
4 |
Correct |
2 ms |
784 KB |
Output is correct |
5 |
Correct |
3 ms |
784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
784 KB |
Expected integer, but "no" found |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
936 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
936 KB |
Expected integer, but "no" found |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
936 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
936 KB |
Output is correct |
2 |
Incorrect |
5 ms |
952 KB |
Expected integer, but "no" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
988 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
1924 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1924 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
3088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |