Girls and Boys
Time Limit: 5000MS |
|
Memory Limit: 10000K |
Total Submissions: 12747 |
|
Accepted: 5678 |
Description in the second year of the University somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it was necessary to find out the the maximum set satisfying the condition:there was no and the students in T He set who has been "romantically involved". The result of the program was the number of students in such a set.
Input the input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:
The number of students
The description of each student, in the following format
Student_identifier: (number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
Or
Student_identifier: (0)
The Student_identifier is a integer number between 0 and n-1 (n <=500), for n subjects.
Output for each given data set, the program should write to standard output a line containing the result.
Sample Input
7
0: (3) 4 5 6 1
: (2) 4 6 2
: (0) 3: (0) 4: (2) 0 1 5: (1) 0 6
: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
Sample Output
5
2
Source Southeastern Europe 2000
——————————————————————————————————
The topic is to give the relationship that n students like, ask the most to choose how many people do not like the relationship
Idea: Maximum independent set, maximum independent set = number of n max matches
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath > #include <algorithm> #include <queue> #include <vector> #include <set> #include <stack&
Gt
#include <map> #include <climits> using namespace std;
#define LL Long Long const int INF = 0X3F3F3F3F;
const int maxn=1000; int un,vn;
u,v number int g[maxn][maxn];//number is 0~n-1 int LINKER[MAXN];
BOOL USED[MAXN];
int MAT[MAXN];
int AA[MAXN];
struct area {int x1,x2,y1,y2;} s[100005];
struct point {int x, y;} p[100005];
bool Dfs (int u) {int V;
for (v=0; v<vn; v++) if (G[u][v]&&!used[v]) {used[v]=true; if (linker[v]==-1| |
DFS (Linker[v])) {linker[v]=u;
return true;
}} return false;
} int Hungary () {int res=0;
int u;
memset (LINKER,-1,SIZEOF (linker)); for (u=0; u<un; u++) {memSet (used,0,sizeof (used));
if (DFS (U)) res++;
} return res;
} int main () {int n,m,x,y;
int Cas=1;
while (~SCANF ("%d", &n)) {memset (g,0,sizeof g);
for (int i=0; i<n; i++) {scanf ("%d: (%d)", &x,&m);
for (int i=0; i<m; i++) {scanf ("%d", &y);
G[x][y]=1;
}} un=vn=n;
printf ("%d\n", N-hungary ()/2);
} return 0; }