HDU Courses 10,832-point match, Hungarian algorithm. Water problem

Source: Internet
Author: User

CoursesTime limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4233 Accepted Submission (s): 2014


Problem Descriptionconsider A group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it was possible to form a committee of exactly P students that satisfies simultaneously t He conditions:

. Every student in the Committee represents a different course (a student can represent a course if he/she visits that cours E

. Each course have a representative in the Committee

Your program should read sets of the data from a text file. The first line of the input file contains the number of the data sets. Each data set was presented in the following format:

P N
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
......
COUNTP STUDENTP 1 studentp 2 ... STUDENTP COUNTP

The first line, each data set contains, positive integers separated by one blank:p (1 <= P <=)-The Numbe R of courses and N (1 <= n <=)-the number of students. The next P lines describe in sequence of the courses. From course 1 to course P, each line describing a course. The description of course I was a line this starts with an integer Count I (0 <= Count i <= N) representing the Numbe R of Students visiting course I. Next, after a blank, you'll find the Count I students, visiting the course, each of the consecutive separated by one blank. Students is numbered with the positive integers from 1 to N.

There is no blank lines between consecutive sets of data. Input data is correct.

The result of the program is in the standard output. For each input data set, prints on a, "YES" if it is possible to form a committee and "NO" otherwise . There should not being any leading blanks at the start of the line.

An example of program input and output:
Sample Input
23 33 1 2 32 1 21 13 32 1 32 1 31 1

Sample Output
Water problem. Hungarian Algorithm Template questions
#include <stdio.h> #include <string.h> #define SIZE 350int pre[size], p, N; bool Map[size][size], Vis[size];i NT find (int pos) {for (int i = 1; I <= n; ++i) {if (!vis[i] && map[pos][i]) {vis[i] = true; if (pre[i] = = 1 | | | fin D (Pre[i])) {pre[i] = pos; return 1;}} return 0;} int main () {int t; scanf ("%d", &t), while (t--) {scanf ("%d%d", &p,&n); memset (map,false,sizeof (map)); Memset ( Pre,-1,sizeof (pre)); for (int i = 1; I <= p; ++i) {int J; scanf ("%d", &j), while (j--) {int C; scanf ("%d", &c); map[i ][c] = true;}} int cnt = 0; for (int i = 1; I <= p; ++i) {memset (vis,false,sizeof (VIS)); cnt + = find (i);} if (cnt==p) puts ("YES"); Elseputs ("NO");} return 0;}
with June

HDU Courses 10,832-point match, Hungarian algorithm. Water problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.