sb问题,出题人题意说的什么G2玩意
#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>
#include<set>
#include<map>
using namespace std;
int n,m,f;
bitset<110> G[110];
bitset<110> F[110];
bitset<110> E;
int par[110];
int find(int x){
return par[x]==x?x:par[x]=find(par[x]);
}
void merge(int x,int y){
par[find(y)]=find(x);
}
int lftto[110],rgtto[110];
bool vis[110];
bool matchpath(int u){
for (int i=1;i<=n;++i){
if (!vis[i] && G[u][i]==1){
vis[i]=1;
if (rgtto[i]==0||matchpath(rgtto[i])){
lftto[u]=i;
rgtto[i]=u;
return true;
}
}
}return false;
}
int hungary(){
fill(lftto,lftto+n+5,0);
fill(rgtto,rgtto+n+5,0);
int ans = 0;
for (int i=1;i<=n;++i){
fill(vis,vis+n+10,0);
if (lftto[i]!=0||matchpath(i))
++ans;
}
return ans;
}
void dele(){
for (int i=1;i<=n;++i)G[i][lftto[i]]=0;
}
int main(){
int tcase;scanf("%d",&tcase);
for (int i=0;i<110;++i)E[i]=0;
while (tcase--){
scanf("%d %d %d",&n,&m,&f);
for (int i=0;i<=n;++i)G[i]&=E,F[i]&=E,par[i]=i;
for (int i=1,u,v;i<=m;++i){
scanf("%d %d",&u,&v);
G[u][v]=1;
}
for (int i=1,u,v;i<=f;++i){
scanf("%d %d",&u,&v);
merge(u,v);
}
for (int i=1;i<=n;++i)F[find(i)]|=G[i];
for (int i=1;i<=n;++i)G[i]|=F[find(i)];
int ans = 0;
while (hungary()==n){
++ans;dele();
}printf("%d\n",ans);
}
}