题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1054
这题水题,因为没有明确的二分关系,所以是一般图匹配。所以最终结果需要除以2.还有需要注意的是,用矩阵会超时,可以用链式前向星。还有就是图是无向图。
代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int n, cnt, head[2000], link[2000], vis[2000];
struct node
{
int u, v, next;
}edge[5000];
void add(int u, int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
int dfs(int u)
{
int i;
for(i=head