# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
898897 | duckindog | Logičari (COCI21_logicari) | C++14 | 23 ms | 7772 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.
// from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
vector<int> ad[N];
int low[N], num[N], it;
vector<int> circle;
bool dd[N];
void dfs(int u, int pre = 0) {
num[u] = low[u] = ++it;
int mku, mkv;
for (int v : ad[u]) {
if (v == pre) continue;
if (num[v]) low[u] = min(low[u], num[v]);
else {
dfs(v, u);
low[u] = min(low[u], low[v]);
}
if (low[v] != num[v]) {
if (!dd[u]) circle.push_back(u);
if (!dd[v]) circle.push_back(v);
dd[u] = dd[v] = 1;
}
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
cin >> n;
bool sub = 1;
for (int i = 1; i <= n; ++i) {
int u, v; cin >> u >> v;
ad[u].push_back(v);
ad[v].push_back(u);
if (ad[u].size() > 2 || ad[v].size() > 2) sub = 0;
}
if (sub) {
cout << (n % 4 == 0 ? n / 2 : -1);
return 0;
}
dfs(1, 0);
for (int x : circle) cout << x << ' ';
}
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... |