题意 给你n个学生每个学生代表的排名范围 然后可能有学生在撒谎 问你有几个学生没撒谎 然后把满足的情况从大到小更新
做法 我们知道查最多满足多少就是跑二分图就好了 但是要从大到小 所以要倒着跑 后来我建边的时候发现 把学生和所有他可能的排名建边太大了 于是发现 如果这个排名范围长度大于学生人数 那么学生无论如何都可以放进一个排名 我们就可以不建边了
于是可以欢乐地跑二分图了
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
const int MAX_N = 120;
const int MAX_M = 4000;
bool use[100025];
int p[MAX_N],eid,girl[100025];
vector<int > ans;
bool cmp(int a,int b)
{
return a >b;
}
void init()
{
eid = 0;
memset(p,-1,sizeof(p));
memset(girl,0,sizeof(girl));
}
struct edge
{
int v,next;
}e[MAX_M];
void add(int u,int v)
{
e[eid].v = v;
e[eid].next = p[u];
p[u] = eid++;
}
bool dfs(int u)
{
for(int i = p[u];i+1;i=e[i].next)
{
int to = e[i].v;
if(!use[to])
{
use[to] = true;
if(!girl[to]||dfs(girl[to]))
{
girl[to] = u;
return true;
}
}
}
return false;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
vector<int > vt;
swap(ans,vt);
init();
int n;
scanf("%d",&n);
for(int i = 1;i<=n;++i)
{
int l,r;
scanf("%d%d",&l,&r);
if(r-l+1>n)
{
ans.push_back(i);
continue;
}
for(int j= l;j<=r;j++)
{
add(i,j);
}
}
for(int i = n;i>=1;--i)
{
memset(use,false,sizeof(use));
if(dfs(i)) ans.push_back(i);
}
printf("%d\n",ans.size());
sort(ans.begin(),ans.end());
for(int i = 0;i<ans.size();++i)
i==ans.size()-1?printf("%d\n",ans[i]):printf("%d ",ans[i]);
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}