#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int mod = (int)1e9 + 7;
const int N = (int)3e4 + 123;
const ll inf = (ll)3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
int n, m, used[1001], p[1001], path[1001][1001];
vector <int> g[1001];
void dfs (int v, int pr = 0) {
p[v] = pr;
used[v] = 1;
int ok = 0;
for (auto to : g[v]) {
if (to == pr) {
if (!ok) {
ok ++;
continue;
}
}
if (used[to] == 2) continue;
if (!used[to]) dfs (to, v);
else {
int x = v;
vector <int> ans;
while (x != to) ans.pb (x), x = p[x];
ans.pb (x);
bool check = 1;
for (int i = 0; i < sz (ans); i ++)
for (int j = i + 2; j < sz (ans); j ++) {
if (i == 0 && j == sz (ans) - 1) continue;
if (path[ans[i]][ans[j]]) check = 0;
}
if (sz (ans) > 3 && check) {
reverse (all (ans));
for (auto it : ans) cout << it << ' ';
exit (0);
}
}
}
used[v] = 2;
}
void rec (int id = 1, string s = "") {
if (id == n + 1) {
vector <int> ans;
bool check = 1;
for (int i = 0; i < n; i ++)
if (s[i] == '1')
ans.pb (i + 1);
if (sz (ans) <= 3) return;
// if (sz(ans) == 4 && ans[0] == 2 && ans[1] == 3 && ans[2] == 4 && ans[3] == 5) cout << "aaa", exit (0);
do {
if (path[ans[0]][ans.back ()] != 1) return;
for (int i = 0; i < sz (ans) - 1; i ++) {
if (path[ans[i]][ans[i + 1]] != 1) check = 0;
for (int j = i + 2; j < sz (ans); j ++) {
if (i == 0 && j == sz (ans) - 1) continue;
if (path[ans[i]][ans[j]] != 0) check = 0;
}
}
}while (next_permutation (all (ans)));
if (check) {
for (auto it : ans) cout << it << ' ';
exit (0);
}
return;
}
rec (id + 1, s + '0');
rec (id + 1, s + '1');
}
inline void boost () {
ios_base :: sync_with_stdio (NULL);
cin.tie (NULL), cout.tie (NULL);
}
inline void Solve () {
cin >> n >> m;
while (m --) {
int x, y;
cin >> x >> y;
path[x][y] ++;
path[y][x] ++;
g[x].pb (y);
g[y].pb (x);
}
if (n <= 20) {
// assert(0);
rec ();
cout << "no", exit (0);
}
for (int i = 1; i <= n; i ++)
if (!used[i])
dfs (i);
cout << "no";
}
main () {
// freopen ("gcm.in", "r", stdin);
// freopen ("gcm.out", "w", stdout);
boost ();
int tt = 1;
// cin >> tt;
while (tt --) {
Solve ();
}
return 0;
}
Compilation message
indcyc.cpp:133:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
508 KB |
Expected integer, but "no" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
508 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
868 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1764 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1764 KB |
Expected integer, but "no" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1764 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
117 ms |
5044 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
5044 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
5044 KB |
Output is correct |
2 |
Execution timed out |
1046 ms |
5044 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |