0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

P2860 [USACO06JAN]Redundant Paths G

https://www.luogu.com.cn/record/77636836
This commit is contained in:
Baoshuo Ren 2022-06-19 19:04:01 +08:00
parent 096df42bd6
commit 3fa4158c4d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

86
Luogu/P2860/P2860.cpp Normal file
View File

@ -0,0 +1,86 @@
#include <iostream>
#include <cstring>
#include <stack>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5005,
M = 10005 << 1;
int f, r, ans;
int idx, head[N], edge[N], next[N];
int cnt, dfn[N], low[N];
int dcc_cnt, siz[N], id[N], in[N];
bool bridge[N];
std::stack<int> st;
void add(int u, int v) {
next[idx] = head[u];
edge[idx] = v;
head[u] = idx++;
}
void tarjan(int u, int in_edge) {
dfn[u] = low[u] = ++cnt;
st.push(u);
for (int i = head[u]; ~i; i = next[i]) {
int v = edge[i];
if (!dfn[v]) {
tarjan(v, i);
low[u] = std::min(low[u], low[v]);
if (dfn[u] < low[v]) {
bridge[i] = bridge[i ^ 1] = true;
}
} else if (i != (in_edge ^ 1)) {
low[u] = std::min(low[u], dfn[v]);
}
}
if (dfn[u] == low[u]) {
dcc_cnt++;
int v;
do {
v = st.top();
st.pop();
id[v] = dcc_cnt;
siz[dcc_cnt]++;
} while (v != u);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(head, 0xff, sizeof(head));
cin >> f >> r;
for (int i = 1, u, v; i <= r; i++) {
cin >> u >> v;
add(u, v);
add(v, u);
}
tarjan(1, -1);
for (int i = 0; i < idx; i++) {
if (bridge[i]) {
in[id[edge[i]]]++;
}
}
for (int i = 1; i <= dcc_cnt; i++) {
if (in[i] == 1) ans++;
}
cout << (ans + 1) / 2 << endl;
return 0;
}