# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244462 | dwsc | Potemkin cycle (CEOI15_indcyc) | C++14 | 1097 ms | 1400 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;
typedef pair<int,int> ii;
int n,m;
vector<int> adj[1010];
int depth[1010],p[1010][10];
int lowest[1010][11];
int relabel[1010];
int counter;
void dfs(int u,int pa){
//cout << u << pa << "hi\n";
depth[u] = depth[pa]+1;
p[u][0] = pa;
for (int i = 1; i <= 10; i++){
if (p[u][i-1] == 0) p[u][i] = 0;
else p[u][i] = p[p[u][i-1]][i-1];
}
for (int i = 0; i < adj[u].size(); i++){
int v = adj[u][i];
if (depth[v] != 0) continue;
dfs(v,u);
}
relabel[u] = ++counter;
}
int lowestjump[1010];
int main(){
cin >> n >> m;
for (int i = 0; i < m; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
for (int i = 1; i <= n; i++){
if (p[i][0] == 0) dfs(i,0);
}
vector<ii> backedges;
for (int i = 1; i <= n; i++){
lowestjump[i] = 1e9;
for (int j = 0; j < adj[i].size(); j++){
int ni = adj[i][j];
if (p[ni][0] == i || p[i][0] == ni) continue;
if (depth[i] < depth[ni]) continue;
lowestjump[i] = min(lowestjump[i],relabel[ni]);
if (depth[i]-depth[ni] >= 3) backedges.push_back(ii(i,ni));
}
}
for (int i = 0; i < backedges.size(); i++){
int minjump = 1e9;
int start = backedges[i].first, fin = backedges[i].second;
if (lowestjump[start] != relabel[fin]) continue;
int temp = start;
while (temp != fin){
temp = p[temp][0];
minjump = min(minjump,lowestjump[temp]);
}
if (minjump <= relabel[fin]) continue;
cout << start << " ";
while (start != fin){
start = p[start][0];
cout << start << " ";
}
return 0;
}
cout << "no";
return 0;
}
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... |