# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156081 | IOrtroiii | 전압 (JOI14_voltage) | C++14 | 173 ms | 21080 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;
const int N = 100100;
int n, m;
vector<int> g[N];
vector<int> tr[N];
int cnt[N];
int ds[N];
int bad;
void dfs1(int v, int p) {
for (int u : g[v]) {
if (u == p) p = 0;
else if (ds[u] && ds[u] < ds[v]) {
// printf("back edge %d -> %d\n", v, u);
if ((ds[v] & 1) == (ds[u] & 1)) {
++bad;
cnt[v]++;
cnt[u]--;
} else {
cnt[v]--;
cnt[u]++;
}
} else if (!ds[u]) {
ds[u] = ds[v] + 1;
tr[v].emplace_back(u);
// printf("tree edge %d -> %d\n", v, u);
dfs1(u, v);
}
}
}
void dfs2(int v) {
for (int u : tr[v]) {
dfs2(u);
cnt[v] += cnt[u];
}
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; ++i) {
int v, u;
scanf("%d %d", &v, &u);
g[v].emplace_back(u);
g[u].emplace_back(v);
}
for (int i = 1; i <= n; ++i) {
if (!ds[i]) {
ds[i] = 1;
dfs1(i, -1);
}
}
for (int i = 1; i <= n; ++i) {
if (ds[i] == 1) {
dfs2(i);
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (ds[i] > 1 && cnt[i] == bad) {
++ans;
}
}
// printf("%d\n", bad);
ans += (bad == 1);
printf("%d\n", ans);
}
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... |