Hoj1083 Problem Solving report

Source: Internet
Author: User

I don't know how to open the zoj website, so I chose a question on hang DIAN to make a picture of the topic. the general meaning of a question is that there are P courses and N students. If each course has a student selection and only one student can select, yes is output; otherwise, no is output. students may have multiple choices, but only one can be selected. A typical Hungarian binary match. If it is a perfect two-point match, the condition is met. note that the student ID starts from 1.

The Code is as follows:


# Include <set>
# Include <map>
# Include <queue>
# Include <stack>
# Include <math. h>
# Include <string>
# Include <vector>
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <limits. h>
# Include <string. h>
# Include <algorithm>
# Include <functional>
Using namespace STD;
Int vis [305] [305];
Int ended [305];
Int match [305];
Int find (int I, int N ){
For (Int J = 1; j <= N; j ++ ){
If (vis [I] [J] &! Ended [J]) {
Ended [J] = 1;
If (Match [J] =-1 | find (Match [J], n )){
Match [J] = I;
Return 1;
}
}
}
Return 0;
}
Int main (){
Int T;
While (scanf ("% d", & T )! = EOF ){
While (t --){
Memset (VIS, 0, sizeof (VIS ));
Memset (match,-1, sizeof (MATCH ));
Memset (ended, 0, sizeof (ended ));
Int P, N, sum = 0, ID;
Scanf ("% d", & P, & N );
For (INT I = 0; I <p; I ++ ){
Scanf ("% d", & sum );
For (Int J = 0; j <sum; j ++ ){
Scanf ("% d", & ID );
Vis [I] [ID] = 1;
}
}
Int res = 0;
For (INT I = 0; I <p; I ++ ){
Memset (ended, 0, sizeof (ended ));
If (find (I, n ))
Res ++;
}
If (RES = P)
Printf ("Yes \ n ");
Else
Printf ("NO \ n ");
}
}
Return 0;
}

Hoj1083 Problem Solving report

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.