HDU 2063过山车(二分最大匹配之最大匹配)
2014-06-06 20:51
435 查看
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063
水题。。纯模板题。。不多说。。
#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, vis[600], head[600], link[600], cnt;
struct node
{
int u, v, next;
} edge[1100];
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[u]; i!=-1; i=edge[i].next)
{
int x=edge[i].v;
if(!vis[x])
{
vis[x]=1;
if(link[x]==-1||dfs(link[x]))
{
link[x]=u;
return 1;
}
}
}
return 0;
}
void hungary()
{
int i, ans=0;
memset(link,-1,sizeof(link));
for(i=1; i<=n; i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",ans);
}
int main()
{
int t, a, b, m;
while(scanf("%d",&t)!=EOF&&t)
{
memset(head,-1,sizeof(head));
scanf("%d%d",&n,&m);
cnt=0;
while(t--)
{
scanf("%d%d",&a,&b);
add(a,b);
}
hungary();
}
return 0;
}
水题。。纯模板题。。不多说。。
#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, vis[600], head[600], link[600], cnt;
struct node
{
int u, v, next;
} edge[1100];
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[u]; i!=-1; i=edge[i].next)
{
int x=edge[i].v;
if(!vis[x])
{
vis[x]=1;
if(link[x]==-1||dfs(link[x]))
{
link[x]=u;
return 1;
}
}
}
return 0;
}
void hungary()
{
int i, ans=0;
memset(link,-1,sizeof(link));
for(i=1; i<=n; i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",ans);
}
int main()
{
int t, a, b, m;
while(scanf("%d",&t)!=EOF&&t)
{
memset(head,-1,sizeof(head));
scanf("%d%d",&n,&m);
cnt=0;
while(t--)
{
scanf("%d%d",&a,&b);
add(a,b);
}
hungary();
}
return 0;
}
相关文章推荐
- HDU 2063 过山车 第一道最大二分匹配
- HDU 2063 BNUOJ 6207 过山车 (最大流or二分匹配)
- HDU 2063 过山车 最大二分匹配
- hdu 2063 过山车(二分最大匹配)
- hdu 2063 过山车(二分最大匹配)
- HDU 2063 过山车 第一道最大二分匹配
- HDU 2063 过山车(最大二分匹配)
- hdu 2063 过山车 基础最大二分匹配
- hdu 2063 过山车(二分图匹配最大匹配数模板)
- hdu 2063 过山车 ( 二分图最大匹配水过 .)
- hdu - 2063 - 过山车(二分图最大匹配)
- Hdu2063—过山车 二分图最大匹配
- hdu 2063 过山车 + hdu 2119 Matrix (二分图的最大匹配边和最小覆盖点)
- hdu 2063 过山车 (二分匹配)
- HDU 2063过山车 二分图最大匹配 匈牙利算法
- hdu 2063 过山车(二分图最大匹配基础)
- hdu 2063 过山车 (二分匹配)
- hdu 2063 过山车(二分图最大匹配,2级)
- HDU 2063 过山车(匈牙利算法 二分图的最小顶点覆盖 二分图最大匹配)
- hdu 2063 过山车 (二分匹配)