COURSES (POJ 1249)

Source: Internet
Author: User

Test instructions

For you P-gate course and N students, a student can choose 0, 1, or more courses, now requires a set of P students, meet the following 2 conditions:

1. Each student chooses a different course

2. Each course has a different representation

If satisfied, the output is yes

Otherwise, the output no

#include <cstdio>#include<iostream>#include<cstring>#defineM 310using namespacestd;intUsed[m],belong[m],a[m][m],p,n;intFindinti) {     for(intj=1; j<=n;j++)      if(!used[j]&&A[i][j]) {Used[j]=1; if(!belong[j]| |find (Belong[j])) {Belong[j]=i; return 1; }      }    return 0;}intMain () {intT; scanf ("%d",&T);  while(t--) {memset (A,0,sizeof(a)); Memset (Belong,0,sizeof(belong)); memset (Used,0,sizeof(used)); scanf ("%d%d",&p,&N);  for(intI=1; i<=p;i++)        {            intx, y; scanf ("%d",&x);  for(intj=1; j<=x;j++) {scanf ("%d",&y); A[i][y]=1; }        }        inttot=0;  for(intI=1; i<=p;i++)          if(Find (i)) {memset (used,0,sizeof(used)); Tot++; }        if(tot==p) printf ("yes\n"); Elseprintf"no\n"); }    return 0;}
View Code

COURSES (POJ 1249)

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.