2014
01-26

# The Accomodation of Students

There are a group of students. Some of them may know each other, while others don’t. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other.

Now you are given all pairs of students who know each other. Your task is to divide the students into two groups so that any two students in the same group don’t know each other.If this goal can be achieved, then arrange them into double rooms. Remember, only paris appearing in the previous given set can live in the same room, which means only known students can live in the same room.

Calculate the maximum number of pairs that can be arranged into these double rooms.

For each data set:
The first line gives two integers, n and m(1<n<=200), indicating there are n students and m pairs of students who know each other. The next m lines give such pairs.

Proceed to the end of file.

For each data set:
The first line gives two integers, n and m(1<n<=200), indicating there are n students and m pairs of students who know each other. The next m lines give such pairs.

Proceed to the end of file.

4 4
1 2
1 3
1 4
2 3
6 5
1 2
1 3
1 4
2 5
3 6

No
3

4 3

2 3

2 4

3 4

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=205;
int flag[N];
int map[N][N];
int match[N];
int n,m;
int bfs()
{
int j;
memset(flag,-1,sizeof(flag));
for(j=1;j<=n;j++)
{
if(flag[j]!=-1) continue;
queue<int> q;
flag[j]=1;
q.push(j);
while(!q.empty())
{
int k=q.front();
q.pop();
for(int i=1;i<=n;i++)
{
if(map[k][i]&&flag[i]==flag[k])
{
return 0;
}
if(map[k][i]&&flag[i]==-1)
{
q.push(i);
flag[i]=1-flag[k];
}
}
}
}
return 1;
}
bool find(int x)
{
int i,k;
for(i=1;i<=n;i++)
{
if(map[x][i]==1)
{
k=i;
{
if(!match[k]||find(match[k]))
{
match[k]=x;
return true;
}
}
}
}
return false;
}
int main()
{
int a,b;
while(~scanf("%d%d",&n,&m))
{
memset(map,0,sizeof(map));
while(m--)
{
scanf("%d%d",&a,&b);
map[a][b]=1;
map[b][a]=1;
}
if(!bfs())
{
printf("No\n");continue;
}
int count=0;
memset(match,0,sizeof(match));
for(int i=1;i<=n;i++)
{
if(find(i))
{
count++;
}
}
printf("%d\n",count/2);
}
return 0;
}

1. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.