You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
804 B
C++
39 lines
804 B
C++
#include <cstdio>
|
|
int head[10010], next[2000010], to[2000010], ecnt, ts;
|
|
int vis[1000010], pre[1000010];
|
|
inline void addEdge(int f, int t)
|
|
{
|
|
ecnt++;
|
|
next[ecnt] = head[f];
|
|
head[f] = ecnt;
|
|
to[ecnt] = t;
|
|
}
|
|
bool dfs(int u)
|
|
{
|
|
for (int cur = head[u], v; cur; cur = next[cur])
|
|
if (vis[to[cur]] != ts)
|
|
{
|
|
v = to[cur], vis[v] = ts;
|
|
if (!pre[v] || dfs(pre[v]))
|
|
{
|
|
pre[v] = u;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
int main()
|
|
{
|
|
int n;
|
|
scanf("%d", &n);
|
|
for (int i = 1, x, y; i <= n; i++)
|
|
{
|
|
scanf("%d%d", &x, &y);
|
|
addEdge(x, i);
|
|
addEdge(y, i);
|
|
}
|
|
for (ts = 1; ts <= 10001; ts++)
|
|
if (!dfs(ts)) break;
|
|
printf("%d", ts - 1);
|
|
return 0;
|
|
} |