After asking all the students, the teacher found that some students didn’t tell the truth. For example, Student1 said he was between 5004th and 5005th, Student2 said he was between 5005th and 5006th, Student3 said he was between 5004th and 5006th, Student4 said he was between 5004th and 5006th, too. This situation is obviously impossible. So at least one told a lie. Because the teacher thinks most of his students are honest, he wants to know how many students told the truth at most.
2 4 5004 5005 5005 5006 5004 5006 5004 5006 7 4 5 2 3 1 2 2 2 4 4 2 3 3 4
3 2 3 4 5 1 3 5 6 7
//
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=110000;
/*初始化
注意 加边时候X和Y统一标号,不是分别标号
cnt=0;
memset(head,-1,sizeof(head));
*/
int n;//X点数
int link[N];
bool used[N];
int head[N],cnt;
struct TT
{
int v,next;
}edge[N*5];
void addedge(int u,int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
bool can(int t)
{
for(int p=head[t];p!=-1;p=edge[p].next)
{
int v=edge[p].v;
if(used[v]==false)
{
used[v]=1;
if(link[v]==-1||can(link[v]))
{
link[v]=t;
return true;
}
}
}
return false;
}
int ans[N],cur;
int MaxMatch()
{
int num=0;
memset(link,-1,sizeof(link));
for(int i=n;i>=1;i--)//题目要标号最大
{
memset(used,false,sizeof(used));
if(can(i))
{
num++;
ans[cur++]=i;
}
}
return num;
}
int main()
{
int ci;scanf("%d",&ci);
while(ci--)
{
scanf("%d",&n);
cnt=0;cur=0;
memset(head,-1,sizeof(head));
for(int i=1;i<=n;i++)
{
int x,y;scanf("%d%d",&x,&y);
for(int j=x;j<=y;j++)
{
addedge(i,j+n);
}
}
printf("%d\n",MaxMatch());
for(int i=cur-1;i>0;i--) printf("%d ",ans[i]);printf("%d\n",ans[0]);
}
return 0;
}