POJ 1274--the Perfect Stall "Two-figure && maximum number of matches && water problem"

Source: Internet
Author: User

The Perfect Stall
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 20795 Accepted: 9386

Description

Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all of the stalls in the new barn is different. For the first week, Farmer John randomly assigned cows to stalls, but it quickly became clear this any given cow is only Willing to produce milk in certain stalls. For the last week, Farmer John had been collecting data on which cows is willing to produce milk in which stalls. A stall may is assigned to one cow, and, of course, a cow is only assigned to one stall.
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that's poss Ible.

Input

The input includes several cases. For each case, the first line contains the integers, n (0 <= n <=) and M (0 <= M <= 200). N is the number of cows, Farmer John has and M are the number of stalls in the new barn. Each of the following N lines corresponds to a single cow. The first integer (SI) on the line is the number of stalls, the cow is willing to produce milk in (0 <= Si <= M) . The subsequent Si integers on this line was the stalls in which that cow was willing to produce milk. The stall numbers is integers in the range (1..M), and no stall would be listed twice for a given cow.

Output

For each case, output a single line with a single integer, the maximum number of milk-producing stall assignments that can be made.

Sample Input

Sample Output

4

Instantaneous seconds of water problem:

#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 220using namespace Std;int n, m; int Map[maxn][maxn];int used[maxn];int link[maxn];void init () {memset (map, 0, sizeof (map));}        void Getmap () {for (int i = 1; I <= n; ++i) {int k;        scanf ("%d", &k);            while (k--) {int A;            scanf ("%d", &a);        Map[i][a] = 1; }}}bool dfs (int x) {for (int i = 1; I <= m; ++i) {if (Map[x][i] &&!used[i]) {Used[i] =            1;                if (link[i] = = 1 | | DFS (LINK[I])) {link[i] = x;            return true; }}} return false;}    int Hungary () {int ans = 0;    memset (link, 1, sizeof);        for (int i = 1; I <= n; ++i) {memset (used, 0, sizeof (used));    if (Dfs (i)) ans++; } return ans;        int main () {while (scanf ("%d%d", &n, &m)! = EOF) {init ();        Getmap ();       int sum = Hungary (); printf ("%d\n", sum); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1274--the Perfect Stall "Two-figure && maximum number of matches && 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.