#include <stdio.h>
#define N 1009
inline char nc() {
static char buf[99999], *l, *r;
return l == r && (r = (l = buf) + fread(buf, 1, 99999, stdin), l == r) ? EOF : *l++;
}
inline void read(int &x) {
char c = nc();
for (; c < '0' || '9' < c; c = nc());
for (x = 0; '0' <= c && c <= '9'; x = (x << 3) + (x << 1) + (c ^ 48), c = nc());
}
int n, f[N], d[N], ans;
bool v1[N], v2[N], e[N][N];
inline int find(int x) {
if (x ^ f[x])
return f[x] = find(f[x]);
return x;
}
main() {
read(n);
ans = n;
for (int i = 0; i < N; f[i] = i, ++i);
for (int u, v; n--;)
read(u), read(v), !e[u][v] && (e[u][v] = 1,
f[find(u)] = find(v), ++d[u], --d[v], v1[u] = v1[v] = 1);
for (int i = 0; i < N; ++i)
if (d[i] > 0)
ans += d[i], v2[find(i)] = 1;
for (int i = 0; i < N; ++i)
if (v1[i])
if (i == f[i])
ans += !v2[i];
printf("%d", ans);
}
一本通1534:原始生物
最新推荐文章于 2024-11-16 21:36:47 发布