"BZOJ1823" [JSOI2010] Feast

Source: Internet
Author: User
Tags uppercase letter

Description

Feast is the most sumptuous banquet dish in China, and there are many different kinds of materials which are presented in a variety of cuisines through Manchu or Han Chinese cuisine. Because of the variety and complexity of the dishes, only a few knowledgeable skilled chefs can make feast, and can cook a feast certified by experts, is also one of the greatest honors of Chinese chefs. The World Feast Association is made up of expert chefs who can cook feast, and they are subdivided into many different levels of chefs. In order to recruit new chefs into the World Feast Association, will be held in the recent feast contest, the association sent many members as assessors, is to be among the chefs in the tournament to find the next star of the Chinese food industry. The rules of the Conference are as follows: Each participant is given n materials, and the player is free to use full or Chinese cuisine to treat the material as a dish. The review system of the General Assembly is: a total of M-judges respectively. Each reviewer has its own unique view of feast, but the basic idea is to have two dishes as a sign of feast. If a judge thinks, if there is no Han-style dongpo meat with full-mutton pot, it can not be regarded as feast. But to avoid too much of a review, the General Assembly stipulates that a reviewer can eliminate a contestant unless he or she considers that the two dishes required are not in place. In other words, as long as the participants can be in the practice of the two materials, one of which meets the review's preferences can be reviewed by this review. If the material has pork, when it comes to mutton and beef, there are four reviewers who like the following table: Review of a review of the second review of the three judges of the four-full-style beef pork chinese style beef chinese beef pork full-style mutton chinese style pork meat full-style lamb, such as a race of pork, full-type mutton and full-style beef dishes, he will not meet The law passed the review. The participant B made Chinese pork, full-style mutton and full-style beef dishes, can meet all the requirements of the review. However, after the General Assembly, it is found that under such a system, if the material selection and the assigned assessors do not have a special arrangement, all the participants can only pass the review of some reviewers rather than all, so there may be no one to pass the examination situation. If four reviewers like the following table, then no matter what the participants do, it is impossible to pass all the evaluation of the assessment: review of a review of the second review of the three judges of the four-full-style mutton pork chinese style mutton chinese style mutton pork full-style mutton pork meat pork so the General Assembly would like someone to write a procedure to judge the chosen M-bit review, will not happen no one can pass the dilemma of assessment, so that the association to organize appropriate jury.

Input

The first line contains a number k, which indicates that the test file contains the K-group data. The first line of each set of test data contains two numbers, N and M (n≤100,m≤1000), representing the n material, and the M-bit reviewer. For ease of access, the material is discarded in Chinese names and given numbers, numbered from 1 to n respectively. The next M-line, each line represents the corresponding reviewers have two preferences, each preference by an English letter with a number, such as M1 on behalf of this review like the 1th material through a full-style cooking dish, and H2 on behalf of the jury like the 2nd material through the Chinese cuisine to cook. Each test file will not have more than 50 sets of test data

Output

Each test data output line, if no one can pass the dilemma of assessment, output good; otherwise output bad (uppercase letter).

Sample Input2
3 4
M3 H1
M1 m2
H1 H3
H3 m2
2 4
H1 m2
M2 M1
H1 H2
M1 H2

Sample OutputGood
Bad
2-sat (bare) problem, it is only my weak slag can be written hanging
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intn=10000;6 structee{intTo,next;} E[n];7 intdnf[2*n],stack[2*n],belong[2*n],head[2*n],low[2*N];8 intt,top,ind,cnt,scc,n,m;9 BOOLs[2*N];Ten int Get(){ One     intx; A     CharC=GetChar (); -      while(c!='m'&&c!='h') c=GetChar (); -     if(c=='m') scanf ("%d", &x), x+=x; the     Elsescanf"%d", &x), x+=x-1; -     returnx; - } -  + voidInsertintUintv) { -E[++cnt].to=v;e[cnt].next=head[u]; head[u]=CNT; + } A  at voidTarjan (intu) { -dnf[u]=low[u]=++IND; -s[u]=1; stack[++top]=u; -      for(intL=head[u];l;l=E[l].next) { -         intv=e[l].to; -         if(!Dnf[v]) { in Tarjan (v); -low[u]=min (low[v],low[u]); to         }  +         Else if(S[v]) { -low[u]=min (low[u],dnf[v]); the         } *     }  $     if(dnf[u]==Low[u]) {Panax NotoginsengScc++; -          while(stack[top]!=u) { thebelong[stack[top]]=SCC; +s[stack[top]]=0; Atop--; the         } +belong[stack[top]]=SCC; -s[stack[top]]=0; $top--; $     } - }  -  the intMain () { -scanf"%d",&T);Wuyi      while(t--){ theTop=ind=cnt=scc=0; -scanf"%d%d",&n,&m); Wu          for(intI=1; i<=2*n;i++) head[i]=dnf[i]=0; -         intX,y,xp,yp; About          for(intI=1; i<=m;i++){ $x=Get(); y=Get(); -             if(%2==0) xp=x--; -             Elsexp=x++; -             if(y%2==0) yp=y--; A             Elseyp=y++; +Insert (xp,y); Insert (YP,X);//Xp,yp said no. the         } -         BOOLflag=0; $          for(intI=1; i<=2*n;i++)if(!dnf[i]) Tarjan (i);//began to write I<=2*2, 1wa. the          for(intI=1; i<=n;i++)if(belong[i*2]==belong[i*2-1])  the{printf ("bad\n"); flag=1; Break;} the         if(!flag) printf ("good\n"); the     } -}

"BZOJ1823" [JSOI2010] Feast

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.