# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311525 | Kenzo_1114 | Potemkin cycle (CEOI15_indcyc) | C++17 | 101 ms | 2724 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int n, m, depth[MAXN], low[MAXN], par[MAXN];
vector<int> graph[MAXN], l[MAXN];
void dfs(int v, int p)
{
depth[v] = (v == p) ? 1 : depth[p] + 1;
par[v] = p;
for(int i = 0; i < (int) graph[v].size(); i++)
{
int u = graph[v][i];
if(depth[u])
{
if(u != p)
{
low[v] = max(low[v], depth[u]);
if(depth[v] - depth[u] >= 3) l[v].push_back(u);
}
continue;
}
dfs(u, v);
}
}
int main ()
{
scanf("%d %d", &n, &m);
for(int i = 0, u, v; i < m; i++)
{
scanf("%d %d", &u, &v);
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(1, 1);
// for(int i = 1; i <= n; i++)
// printf("i = %d par = %d depth = %d low = %d\n", i, par[i], depth[i], low[i]);
vector<int> ans;
for(int i = 1; i <= n; i++)
{
bool ok;
for(int j = 0; j < l[i].size(); j++)
{
int cur = i;
ok = !(low[cur] > depth[l[i][j]]);
ans.push_back(cur);
while(cur != l[i][j])
{
cur = par[cur];
if(cur != l[i][j] && low[cur] >= depth[l[i][j]]) ok = false;
ans.push_back(cur);
}
if(ok) break;
else ans.clear();
}
if(ok) break;
}
if(ans.empty()) printf("no\n");
else
{
for(int i = 0; i < (int) ans.size(); i++) printf("%d ", ans[i]);
printf("\n");
}
}
/*
5 6
1 2
1 3
2 3
4 3
5 2
4 5
4 5
1 2
2 3
3 4
4 1
1 3
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |