Volunteering (Codevs 2930)

Source: Internet
Author: User

Title Description Description

The college entrance examination is over, and voluntary reporting is underway.

Wu Principal's school has n students, each student has ki a willing to go to the university. In teacher Wu's province, there is an admission quota for m universities. According to previous experience, for each university (number CI), only one person in the school will be admitted. Therefore, in order to avoid the voluntary conflict, every year Wu principals to arrange teachers to the students to adjust their volunteer.

This year, the president has found you to help, please program calculation, in the case of no conflict, the maximum number of students can successfully fill out the volunteer, and how to fill out the voluntary program.

Enter a description Input Description

The first line, a number n.

The next n rows, the first number of each row is Ki, followed by the number of Ki, indicating the number of the university that I am willing to go to.

The next line, a number m.

The next line, m number, is the number of M universities. Ensure that the university number is incremented.

Output description Output Description

The first line, a number, in the case of no conflict, the maximum number of students can successfully fill out the volunteer.

In the next few lines, the output is a voluntary scheme. Two numbers per line, the first number is student number, the second number is the university number, separated by a space. If there are many feasible schemes, the output dictionary order is the smallest one.

Sample input Sample Input

3

2 1 2

3 2 4 5

2 2 3

5

1 3 4) 5 6

Sample output Sample Output

3

1 1

2 4

3 3

Data range and Tips Data Size & Hint

0<n<=1000,0<ki<=20,0<m<=2000, the student's number is 1~n, the university's number is 1~5000. Students are willing to go to the university does not necessarily recruit.

#include <cstdio>#include<iostream>#include<cstring>#defineM 5010#defineN 1010using namespacestd;intline[n][m],used[m],belong[m],vis[m],sch[m],n,m;intFindintx) {     for(intI=1; i<=m;i++)      if(line[x][i]&&!used[i]&&Sch[i]) {Used[i]=1; if(!belong[i]| |find (Belong[i])) {Belong[i]=x; return 1; }      }    return 0;}intMain () {scanf ("%d",&N); intx, y;  for(intI=1; i<=n;i++) {scanf ("%d",&x);  for(intj=1; j<=x;j++) {scanf ("%d",&y); Line[i][y]=1; }    }    inte; scanf ("%d",&e);  for(intI=1; i<=e;i++) {scanf ("%d",&x); SCH[X]=1; M=Max (m,x); }    inttot=0;  for(intI=1; i<=n;i++) {memset (used,0,sizeof(used)); if(Find (i)) tot++; } printf ("%d", tot); return 0;}
View Code

Volunteering (Codevs 2930)

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.