code
看第82行
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#define X 20005
#define ll long long
#define maxn 100050
using namespace std;
inline int Max(int a,int b)
{
return a>b?a:b;
}
inline int scan()
{
register int x=0;
register char c=getchar();
bool f=0;
while(c<'0'||c>'9')c=='-'?f=1:f,c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f?-x:x;
}
inline void print(int k,char ch=0)
{
if(k<0)k=-k,putchar('-');
if(k>=10)print(k/10,0);
putchar(k%10+'0');
if(ch)putchar(ch);
}
int n,match[3000010],a,b,total,ans,head[3000010],T,cnt,temp;
struct EDGE
{
int to,Next,w;
bool operator < (const EDGE &b)const {return this->w<b.w;}
bool operator <= (const EDGE &b)const {return this->w<=b.w;}
bool operator > (const EDGE &b)const {return this->w>b.w;}
bool operator >= (const EDGE &b)const {return this->w>=b.w;}
}edge[40000000];
inline void add_edge(int u,int v)
{
total++;
edge[total].Next=head[u];
edge[total].to=v;
head[u]=total;
}
int MM=0;
bool book[1000050];
inline bool dfs(int s)
{
if (s==-1) return false;
int e=head[s],Next;
while (e)
{
Next=edge[e].to;
MM=Max(MM,Next);
if (!book[Next])
{
book[Next]=true;
if (!match[Next]||dfs(match[Next]))
{
match[Next]=s;
return true;
}
}
e=edge[e].Next;
}
return false;
}
int main()
{
n=scan();
for (int i=1;i<=n;i++)
{
a=scan();b=scan();
add_edge(a,i);
add_edge(b,i);
}
for (int i=1;i<=10000;i++)
{
memset(book,false,sizeof(book));//用memset把book数组全部清空不会tle
//fill(book+1,book+1+MM,false);//但是用 fill这么刷数组会 t4个点
//MM 是遍历过程中 经过的最大的点
MM=0;
if (!dfs(i))
{
printf("%d",i-1);
return 0;
}
}
printf("10000");
return 0;
}