标签:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) #define N 10010 #define M 1000010 using namespace std; typedef long long llg; int n,pip[M],vis[M],cnt; int head[N],next[M<<1],to[M<<1],tt; int getint(){ int w=0;bool q=0; char c=getchar(); while((c>‘9‘||c<‘0‘)&&c!=‘-‘) c=getchar(); if(c==‘-‘) c=getchar(),q=1; while(c>=‘0‘&&c<=‘9‘) w=w*10+c-‘0‘,c=getchar(); return q?-w:w; } void link(int x,int y){to[++tt]=y;next[tt]=head[x];head[x]=tt;} bool dfs(int u){ for(int i=head[u],v;i;i=next[i]) if(vis[to[i]]!=cnt){ v=to[i]; vis[v]=cnt; if(!pip[v] || dfs(pip[v])){ pip[v]=u; return 1; } } return 0; } int main(){ n=getint(); for(int i=1;i<=n;i++) link(getint(),i),link(getint(),i); for(int i=1;i<=10000;i++){ cnt++; if(!dfs(i)){ printf("%d",i-1); return 0; } } printf("10000"); }
标签:
原文地址:http://www.cnblogs.com/lcf-2000/p/5924418.html