#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 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);
for (int i = 1; i <= n; i++) {
for (int j: adj[i]) {
int v2 = U[j]^V[j]^i;
for (int k: adj[v2]) {
int u = U[k]^V[k]^v2;
if (mrk[u]==0&&nei[u][i])
mrk[u] = 1;
}
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 (mrk[u]==1&&nei[u][i])
mrk[u] = 0;
}
mrk[i] = 2;
}
}
printf("no\n");
return 0;
}
Compilation message
indcyc.cpp: In function 'int main()':
indcyc.cpp:104: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:106: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 |
504 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 |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
496 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
20 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
820 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
17 ms |
760 KB |
Output is correct |
4 |
Correct |
169 ms |
928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
760 KB |
Output is correct |
2 |
Correct |
197 ms |
804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
498 ms |
2564 KB |
Output is correct |
2 |
Correct |
163 ms |
2172 KB |
Output is correct |
3 |
Execution timed out |
1071 ms |
2744 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
1912 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
1912 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
265 ms |
2904 KB |
Output is correct |
2 |
Execution timed out |
1076 ms |
2936 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |