# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1176373 | anha3k25cvp | Potemkin cycle (CEOI15_indcyc) | C++20 | 249 ms | 92176 KiB |
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>
using namespace std;
const int N = 1 + 1e3;
const int inf = 7 + 1e9;
struct Edge {
int u, v;
};
int node = 0;
vector <Edge> e;
vector <int> num, low, used, ans;
vector <vector <int>> adj;
stack <int> q;
void dfs(int u) {
num[u] = low[u] = ++ node;
q.push(u);
for (int v : adj[u]) {
if (!num[v]) {
dfs(v);
low[u] = min(low[u], low[v]);
}
else
low[u] = min(low[u], num[v]);
}
if (num[u] == low[u]) {
int v = 0;
vector <int> c;
while (v != u) {
v = q.top(); q.pop();
num[v] = low[v] = inf;
c.push_back(v);
}
if (c.size() > 1)
ans = c;
}
}
int main() {
#define TASKNAME ""
ios_base :: sync_with_stdio (0);
cin.tie (0);
if ( fopen( TASKNAME".inp", "r" ) ) {
freopen (TASKNAME".inp", "r", stdin);
freopen (TASKNAME".out", "w", stdout);
}
int n, m;
cin >> n >> m;
e.resize(2 * m + 2);
adj.resize(2 * m + 2);
vector <vector <int>> f(n + 1, vector <int> (n + 1, 0));
for (int i = 1; i <= m; i ++) {
cin >> e[i].u >> e[i].v;
f[e[i].u][e[i].v] = i * 2;
f[e[i].v][e[i].u] = i * 2 + 1;
}
for (int i = 1; i <= m; i ++) {
int u = e[i].u, v = e[i].v;
for (int w = 1; w <= n; w ++)
if (w != u && w != v) {
if (f[v][w] && !f[u][w])
adj[i * 2].push_back(f[v][w]);
if (f[u][w] && !f[v][w])
adj[i * 2 + 1].push_back(f[u][w]);
}
}
for (int i = m; i > 0; i --) {
e[2 * i] = e[i];
e[2 * i + 1] = {e[i].v, e[i].u};
}
num.assign(2 * m + 2, 0);
low.assign(2 * m + 2, 0);
used.assign(2 * m + 2, 0);
for (int i = 2; i < 2 * m + 2; i ++)
if (!num[i])
dfs(i);
if (ans.empty()) {
cout << "no";
return 0;
}
for (int i : ans)
cout << e[i].u << ' ';
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... |