NC20483
想象人找床,不管床找人,即可解决问题
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128=__int128;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using db = double;
using ldb = long double;
#define F first
#define S second
void solve(){
int n;cin>>n;
vector<pii> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i].F;
}
for(int i=1;i<=n;i++){
cin>>a[i].S;
}
vector<vector<int>> adj(n+1,vector<int>(n+1));
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>adj[i][j];
}
}
for(int i=1;i<=n;i++){
if(a[i]==(pii){1,0}) adj[i][i]=1;
}
vector<bool> vis(n+1);
vector<int> link(n+1);
auto dfs=[&](auto&& self,int u)->int {
for(int i=1;i<=n;i++){
if(!adj[u][i]||vis[i]) continue;
if(!a[i].F) continue;
vis[i]=true;
if(!link[i]||self(self,link[i])){
link[i]=u;
return 1;
}
}
return 0;
};
int ans=1;
for(int i=1;i<=n;i++){
if(a[i]==(pii){1,1}) continue;
vis.assign(n+1,false);
ans=ans&dfs(dfs,i);
// cout<<ans<<"\n";
}
if(ans){
cout<<"^_^\n";
}else{
cout<<"T_T\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}

京公网安备 11010502036488号