//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e3 + 5;
const int MAXM = 1e5 + 5;
const double eps = 1e-9;
int U[MAXM], V[MAXM], ap[MAXM];
int mrk[MAXN], dist[MAXN];
int lo[MAXN], disc[MAXN], ti = 1, par[MAXN];
vi adj[MAXN];
bool nei[MAXN][MAXN];
void dfs(int u, int p=0) {
lo[u] = disc[u] = ti++;
for (int i: adj[u]) {
int v = U[i]^V[i]^u;
if (!disc[v]) {
dfs(v, u);
lo[u] = min(lo[u], lo[v]);
if (lo[v] > disc[u])
ap[i] = 1;
} else if (v != p)
lo[u] = min(lo[u], disc[v]);
}
}
void dfs2(int u, int p) {
lo[u] = p;
for (int i: adj[u]) {
int v = U[i]^V[i]^u;
if (par[v] == u)
dfs2(v, p);
}
}
stack<int> st;
void solve(int u, int root) {
int nx = -1, d = INF;
for (int i: adj[u]) {
int v = U[i]^V[i]^u;
if (mrk[v] || par[v] == u || v == par[u] || dist[v] == 0 || lo[u] == lo[v]) continue;
if (dist[v] < d)
tie(nx, d) = mp(v, dist[v]);
}
st.push(u);
if (nx != -1) {
vi tmp;
while (par[nx] != nx) {
tmp.pb(nx);
nx = par[nx];
}
reverse(tmp.begin(), tmp.end());
while (!st.empty()) {
printf("%d ", st.top());
st.pop();
}
for (int i: tmp)
printf("%d ", i);
printf("\n");
exit(0);
}
for (int i: adj[u]) {
int v = U[i]^V[i]^u;
if (par[v] == u)
solve(v, root);
}
st.pop();
}
int b[MAXN];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d", U+i, V+i);
adj[U[i]].pb(i);
adj[V[i]].pb(i);
nei[U[i]][V[i]] = 1;
nei[V[i]][U[i]] = 1;
}
for (int i = 1; i <= n; i++) {
if (!disc[i])
dfs(i);
b[i] = i;
}
srand(time(0));
random_shuffle(b+1, b+n+1);
for (int ii = 1; ii <= n; ii++) {
int i = b[ii];
set<ll> hshmrk;
for (int j: adj[i]) {
int v2 = U[j]^V[j]^i;
ll hsh = 0;
for (int k: adj[v2]) {
int u = U[k]^V[k]^v2;
if (nei[u][i]) {
hsh = (hsh * 1009ll + u) % MOD;
mrk[u] = 1;
}
}
if (hshmrk.count(hsh))
continue;
mem(dist, 0);
mem(par, 0);
deque<int> pq; pq.pb(i);
par[i] = i;
while (!pq.empty()) {
int u = pq.front(); pq.pop_front();
for (int k: adj[u]) {
int v = U[k]^V[k]^u;
if (par[v] || mrk[v]) continue;
par[v] = u;
dist[v] = dist[u] + 1;
pq.pb(v);
}
}
mem(lo, 0);
for (int j: adj[i]) {
int v = U[j]^V[j]^i;
if (!mrk[v])
dfs2(v, v);
}
st.push(i);
solve(v2, i);
while (!st.empty()) st.pop();
for (int k: adj[v2]) {
int u = U[k]^V[k]^v2;
if (nei[u][i])
mrk[u] = 0;
}
hshmrk.insert(hsh);
}
for (int j = 1; j <= n; j++) {
if (!nei[i][j])
continue;
nei[i][j] = nei[j][i] = 0;
for (int l = 0; l < adj[j].size(); l++) {
if (U[adj[j][l]] != i && V[adj[j][l]] != i)
continue;
swap(adj[j].back(), adj[j][l]);
break;
}
adj[j].pop_back();
}
if (ii > 50 && n > 100)
break;
}
printf("no\n");
return 0;
}
Compilation message
indcyc.cpp: In function 'int main()':
indcyc.cpp:173:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int l = 0; l < adj[j].size(); l++) {
~~^~~~~~~~~~~~~~~
indcyc.cpp:106:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", U+i, V+i);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
504 KB |
Output is correct |
2 |
Correct |
13 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
10 ms |
760 KB |
Output is correct |
4 |
Correct |
44 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
760 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
2352 KB |
Output is correct |
2 |
Correct |
378 ms |
2168 KB |
Output is correct |
3 |
Execution timed out |
1080 ms |
2296 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
446 ms |
1912 KB |
Output is correct |
2 |
Correct |
904 ms |
1836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
2552 KB |
Output is correct |
2 |
Correct |
372 ms |
2612 KB |
Output is correct |
3 |
Execution timed out |
1083 ms |
2680 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |