爆零求助
查看原帖
爆零求助
289587
Williamkong楼主2020/8/11 16:30

思路:二分图

贴代码:

#include <bits/stdc++.h>
using namespace std;

const int N = 100;

vector<int> g[N];
int t, n, school[N], home[N], tot;
int x, ans, match[N];
bool vis[N];

bool dfs(int now)
{
	for (int i = 0; i < g[now].size(); i++)
	{
		int v = g[now][i];
		if(!vis[v])
		{
			vis[v] = true;
			if (!match[v] || dfs(match[v]))
			{
				match[v] = now;
				return 1;
			}
		}
	}
	return 0;
}

int main()
{
	cin >> t;
	while (t--)
	{
		tot = 0;
		ans = 0;
		memset(match, 0, sizeof(match));
		memset(home, 0, sizeof(home));
		memset(school, 0, sizeof(school));
		memset(vis, 0, sizeof(vis));
		
		cin >> n;	
		for (int i = 1; i <= n; i++)
			cin >> school[i];
			
		for (int i = 1; i <= n; i++)
		{
			cin >> home[i];
			if (school[i] && !home[i]) g[i].push_back(i);	
		}
		
		for (int i = 1; i <= n; i++)
			if (!school[i] || (school[i] && !home[i]))
				tot++;
				
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
			{
				cin >> x;
				if (x && school[j])
				{
					g[i].push_back(j);
					g[j].push_back(i);
				}
			}
		
		for (int i = 1; i <= n; i++)
		{
			if ((school[i] && !home[i]) || !school[i])
			{
				memset(vis, 0, sizeof(vis));
				if (dfs(i)) ans++;
			}
		}
		
		if (ans == tot)
			cout << "^_^" << endl;
		else
			cout << "T_T" << endl;
	}
	
	return 0;
}

求高人debug!

2020/8/11 16:30
加载中...