您的位置:首页 > 理论基础 > 计算机网络

2008年第33届ACM/ICPC亚洲区预赛(哈尔滨)网络预选赛 1007__The Accomodation of Students 二分图最大匹配+染色

2008-10-02 08:51 489 查看
http://acm.hrbeu.edu.cn/index.php?act=problem&proid=5087

之前完全不会的说....太弱小了

想了半天终于知道啥是染色....

不过现在会了,会了总比不会好-,-

题目的意思就是把学生分成2组,每组中的学生都不互相认识,可是2组间的任何学生都认识,很明显是匹配问题,比赛的时候瞬间被无数人秒杀..

具体思路代码写的非常清楚了...

#include <iostream>

using namespace std;

#define N 201

bool map

,visit
;

int n,m,match
,color
;

bool dfs(int pre)

{

for(int i=1;i<=m;i++)

{

if(map[pre][i]&&!visit[i])

{

visit[i]=true;

int t=match[i];

match[i]=pre;

if(t==-1||dfs(t)) return true;

match[i]=t;

}

}

return false;

}

int find_match()

{

memset(match,-1,sizeof(match));

int i,sum=0;

for(i=1;i<=n;i++){memset(visit,false,sizeof(visit));if(dfs(i)) sum++;}

return sum;

}

int main()

{

int x,y,t;

bool flag;

while(cin>>n>>t)

{

memset(map,false,sizeof(map));

memset(color,0,sizeof(color));

m=n;

flag=false;

while(t--)

{

cin>>x>>y;

if(color[x]&&color[x]==color[y])flag=true;

color[x]=1;

color[y]=2;

map[x][y]=true;

}

if(flag)

cout<<"No"<<endl;

else

cout<<find_match()<<endl;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐