爆零求大佬
查看原帖
爆零求大佬
615236
FF_pigeon楼主2023/8/15 16:17
#include<bits/stdc++.h>
using namespace std;
const int E = 4e4+100;
const int N = 500+10;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n, t, ecnt = 1, tot;
struct Edge{
	int to,nxt;
}e[E];
int vis[N], mch[N], head[E];
void addedge( int u , int v ){
	e[++ecnt].to = v;
	e[ecnt].nxt = head[u];
	head[u] = ecnt;
}
bool dfs( int x ){
	if( vis[x] == 1 )return false;
	vis[x] = 1;
	for( int i = head[x] ; i ; i = e[i].nxt )
		if( ( mch[e[i].to] == 0 ) || dfs(mch[e[i].to])){
			mch[e[i].to] = x;
			return true;
		}
	return false;
}
void clear(){
	memset(head,0,sizeof(head));
	for( int i = 1 ; i <= N ; ++i ){
		vis[i] = mch[i] = 0;
	}
	for( int i = 1 ; i <= E ; ++i ){
		e[i].to = e[i].nxt = 0;
	}
	ecnt = 1;
	tot = 0;
	n = 0;
}
int main(){
	
	t = read();
	int a;
	while( t-- ){
		n = read();
		for( int i = 1 ; i <= n ; ++i ){
			for( int j = 1 ; j <= n ; ++j ){
				a = read();
				if( a == 1 )addedge(i,j+n);
			}
		}
		for( int i = 1 ; i <= n*2 ; ++i ){
			if( dfs(i) )tot++;
		}
		if( tot >= n )cout << "Yes" << endl;
		else cout << "No" << endl;
		clear();
	}
	return 0;
}

谢谢大佬~~(生无可恋)~~

2023/8/15 16:17
加载中...