思路:正好是二分图,自己敌人,符合条件的随从二人组建边,最大匹配为n是符合要求
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int,int>pii;
const int N=1e2+;
const int INF=0x3f3f3f3f;
int match[N<<],T,n;
bool vis[N<<];
int a[N<<],b[N<<];
vector<int>g[N];
bool dfs(int u){
for(int i=;i<g[u].size();++i){
int v=g[u][i];
if(vis[v])continue;
vis[v]=true;
if(match[v]==-||dfs(match[v])){
match[v]=u;
return true;
}
}
return false;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=;i<=*n;++i){
scanf("%d%d",&a[i],&b[i]);
}
for(int i=;i<=n;++i)g[i].clear();
for(int i=;i<=n;++i)
for(int j=n+;j<=*n;++j)
if(a[i]>b[j]&&b[i]>=a[j])g[i].push_back(j);
int ans=;
memset(match,-,sizeof(match));
for(int i=;i<=n;++i){
memset(vis,false,sizeof(vis));
if(dfs(i))++ans;
} if(ans==n)printf("Yes\n");
else printf("No\n");
}
return ;
}