HDU 1083 courses (maximum binary matching)

Source: Internet
Author: User

This question is very simple. At first glance, we can see that it is the biggest matching question of binary. As long as it is used to contact the template.

Code:

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int Ln = 110; const int Rn = 310; int ln, RN; int G [Ln] [Rn], CX [Ln], CY [Rn]; // store the matching bool used [Rn]; bool DFS (int u) {for (INT v = 1; v <= rn; ++ v) if (G [u] [v] &! Used [v]) {used [v] = true; If (CY [v] =-1 | DFS (CY [v]) {CY [v] = u; CX [u] = V; return 1 ;}} return 0 ;}int match () {int res = 0; memset (CX, -1, sizeof (CX); memset (CY,-1, sizeof (CY); For (INT u = 1; U <= ln; ++ U) {memset (used, 0, sizeof (used); If (DFS (u) RES ++;} return res ;}int main () {int T; scanf ("% d", & T); While (t --) {memset (G, 0, sizeof (g); scanf ("% d ", & ln, & RN); For (INT I = 1; I <= ln; ++ I) {int num; scanf ("% d", & num ); while (Num --) {int V; scanf ("% d", & V); G [I] [v] = 1 ;}} if (MATCH () = ln) printf ("Yes \ n"); else printf ("NO \ n ");}}

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.