# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365989 | kostia244 | Potemkin cycle (CEOI15_indcyc) | C++17 | 844 ms | 6516 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>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int maxn = 1002, maxm = 2e5 + 3;
int can[maxm][maxn], hv[maxn][maxn], vis[maxm], n, m;
vector<array<int, 2>> edges;
vector<int> cur;
void reduce() {
int r = 0;
while(r < cur.size()) {
int ok = 1;
for(int i = 1; i+1 < r; i++) {
ok &= !hv[cur[r]][cur[i]];
}
if(!ok) break;
if(r > 1 && hv[cur[r]][cur[0]]) {r++;break;}
r++;
}
for(int i = 0; i < r; i++) cout << cur[i] << " "; cout << endl;
exit(0);
}
void dfs(int ed) {
vis[ed] = 2;
auto [st, en] = edges[ed];
cur.push_back(en);
for(int i = 1; i <= n; i++) if(i != st && i != en) {
if(hv[i][en] && hv[i][st]) continue;
if(!hv[en][i]) continue;
if(!vis[hv[en][i]-1]) {
dfs(hv[en][i]-1);
} else if(vis[hv[en][i]-1] == 2) {
reverse(all(cur));
while(cur.back() != en) cur.pop_back();
cur.pop_back();
reduce();
}
}
vis[ed] = 1;
cur.pop_back();
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
edges.resize(m);
for(auto &[f, t] : edges) {
cin >> f >> t;
}
for(int i = 0; i < m; i++) edges.push_back({edges[i][1], edges[i][0]});
for(int i = 0; i < 2*m; i++) hv[edges[i][0]][edges[i][1]] = i+1;
for(int i = 0; i < 2*m; i++) if(!vis[i]) {
cur = {edges[i][0]};
dfs(i);
}
cout << "no\n";
}
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... |