# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
460992 | kingfran1907 | Potemkin cycle (CEOI15_indcyc) | C++14 | 1091 ms | 5500 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 X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 1010;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;
int n, m;
vector< int > graph[maxn];
int eg[maxn][maxn];
int dis[maxn];
queue< int > q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
graph[a].push_back(b);
graph[b].push_back(a);
eg[a][b] = eg[b][a] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < graph[i].size(); j++) {
for (int k = j + 1; k < graph[i].size(); k++) {
int x = graph[i][j];
int y = graph[i][k];
if (eg[x][y]) continue;
for (int p = 1; p <= n; p++) dis[p] = inf;
dis[i] = -1;
for (int tren : graph[i]) dis[tren] = -1;
dis[y] = inf; dis[x] = 0;
q.push(x);
while (!q.empty()) {
int node = q.front();
q.pop();
for (int tren : graph[node]) {
if (dis[tren] == inf) {
dis[tren] = 1 + dis[node];
q.push(tren);
}
}
}
if (dis[y] == inf) continue;
vector< int > v;
int ptr = y;
while (ptr != x) {
v.push_back(ptr);
for (int tren : graph[ptr]) {
if (dis[tren] + 1 == dis[ptr]) {
ptr = tren;
break;
}
}
}
printf("%d %d ", i, x);
reverse(v.begin(), v.end());
for (int i = 0; i < v.size(); i++)
printf("%d ", v[i]);
printf("\n");
return 0;
}
}
}
printf("no\n");
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... |