1433: [ZJOI2009] Holiday Dorm

Source: Internet
Author: User

Time Limit:10 Sec Memory limit:162 MB
submit:4157 solved:1805
[Submit] [Status] [Discuss]
DescriptionSchool is on holiday ... Some students go home, and some students have former friends to visit, then the accommodation is a problem. Like a .and B are school students, a to go home, and C to see B,C and a Do not know. We assume that everyone can only sleep and be directly acquainted with the person's bed. So asolution is b sleep a bed and C sleep B bed. And the actual situation may be very complex, some people may know a lot of students in school, between school students alsoNot necessarily all know each other. We know that there are a total of n individuals, and that each of them is not a student of the university, and that each student is home. Ask if there is a plan that will allow all students who do not go home and others who visit them to have a place to live.  InputThe first line, a number t, represents the number of data groups. Next to the T-group data,the first row of each group of data n indicates the total number of people involved. the next line n number, the number of I indicates whether the first person is a school student (0 means no, 1 means yes). then the next line n number, the number of I indicates whether the first person is home(0 means do not go home, 1 means go home, note if the first person is not a school student, then the number in this position is a random number,you should ignore it after reading it). Next n rows n number of rows per row,the number of J in line I indicates whether I and J recognize(1 is recognized, 0 is not recognized, the first row I is a value of 0, but obviously I can still sleep in their own bed),The relationship of cognition is mutual. 1≤n≤50,1≤t≤20 Outputfor each set of data, if there is a scenario, output "^_^" (without quotation marks) otherwise output "t_t" (without quotation marks). (Note that the output is half-width characters, that is, the ASCII code for three symbols is 94,84,95)Sample Input1
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0
Sample Outputˆˆalmost bare binary graph matching
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 intt,n,sn,gn;7 inta[ -],b[ -],match[ -];8 BOOLmp[ -][ -],vis[ -];9 BOOLFlag;Ten  One BOOLFindintx) A { -      for(intI=1; i<=n;i++) -         if(mp[x][i]&&!Vis[i]) the         { -vis[i]=1; -             if(match[i]==0||find (Match[i])) -             { +match[i]=x; -                 return true; +             } A         } at     return false; - } -  - intMain () - { -scanf"%d",&T); in      while(t--) -     { toflag=1; +memset (Match,0,sizeof(Match)); -scanf"%d",&n); the          for(intI=1; i<=n;i++) scanf ("%d",&a[i]); *          for(intI=1; i<=n;i++) $         {Panax Notoginsengscanf"%d",&b[i]); -             if(!a[i]) b[i]=0; the         } +          for(intI=1; i<=n;i++) A              for(intj=1; j<=n;j++) the             { +                 intx; -scanf"%d",&x); $                 if(I==J) x=1; $                 if(a[j]&&x) mp[i][j]=1; -                 Elsemp[i][j]=0; -             } the          for(intI=1; i<=n;i++) -         {Wuyimemset (Vis,0,sizeof(Vis)); the             if(!b[i]&&!find (i)) -             { Wuflag=0; -                  Break; About             } $         } -         if(flag) printf ("^_^ \ n"); -         Elseprintf"t_t\n"); -     } A     return 0; +}

1433: [ZJOI2009] Holiday Dorm

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.