只有一个简单的字符数组更新不会
查看原帖
只有一个简单的字符数组更新不会
1168588
FASTergood楼主2024/7/17 19:20

这里怎么更新鸭???

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<cmath>
using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

const int N = 500 + 10, M = 1e5+ 10, MAXI = 0x3f3f3f3f;

int n,  k;
int  m;
char s[N];
int h[N], e[M], ne[M], idx;
int match[N];
bool st[N];
int cnt;
void add(int a, int b)
{
	e[idx] = b;ne[idx] = h[a];h[a] = idx++;
}
bool find(int u)
{
	for (int i = h[u];i != -1;i = ne[i])
	{
		int j = e[i];
		if (!st[j])
		{
			st[j] = true;
			if (match[j] == 0 || find(match[j]))
			{
				match[j] = u;
				return true;
			}
		}
	}
	return false;
}
void clear()
{
	
	cnt = 0;
	for (int i = 1; i <= idx; i++)
	{
		ne[i] = e[i] = 0;
		h[i] = -1;
	}
	idx = 0;
	for (int i = 1; i <=m; i++)
	{
		match[i] = 0;
	}
}
int main()
{
	cin >> n;
	while (n--) {
		//memset(s,"", sizeof(s));
		
		cin >> m;
		
		for (int i = 1;i <= m;i++)
		{
			scanf("%s", s + 1);
			for (int j = 1;j <= m;j++)
			{
				if (s[j] =='1')
					add(i,j);
			}
		}
		//注意看就是这里不会更新直接全wa,请问这种存邻接矩阵的写法怎么更新呢?
			
		for (int i = 1;i <= m;i++)
		{
			memset(st, false, sizeof(st));
			if (find(i))cnt++;
		}
		if (cnt >= m)cout << "Yes" << endl;
		else cout << "No" << endl;
		clear();
	}
	return 0;
}
2024/7/17 19:20
加载中...