Time Limit:10 Sec Memory limit:64 MB
submit:1640 solved:798
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 meat chinese style beef Chinese beef pork full-style mutton chinese style pork meat full-style mutton, such as the race to make pork, full-style mutton and full-style beef dishes, he will Cannot pass 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 chinese style pork full-style mutton pork full-style pork so the assembly wants someone to write a procedure to judge the Review, will not happen no one can pass the dilemma of assessment, so that the association to organize the 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
Hintsource
JSOI2010 Second round Contest2
2-sat Nude Questions
Building the Edge: For a jury needs two courses, if not selected one, you must choose the second way.
After the indentation, if there is a ring, the description is not feasible.
1 /*by Silvern*/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 #defineLL Long Long8 using namespacestd;9 Const intmxn= the;Ten intRead () { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - intn,m; - structedge{ - intv,nxt; +}e[mxn<<1]; - inthd[mxn],mct=1; + voidAdd_edge (intUintv) { Ae[++mct].v=v;e[mct].nxt=hd[u];hd[u]=MCT; at return; - } - intDfn[mxn],low[mxn],dtime=0; - BOOLINST[MXN]; - intst[mxn],top=0; - intBelone[mxn],cnt=0; in voidTarjan (intu) { -dfn[u]=low[u]=++Dtime; tost[++top]=u; +inst[u]=1; - for(intI=hd[u];i;i=e[i].nxt) { the intv=e[i].v; * if(!Dfn[v]) { $ Tarjan (v);Panax Notoginsenglow[u]=min (low[u],low[v]); - } the Else if(Inst[v]) low[u]=min (low[u],dfn[v]); + } A if(dfn[u]==Low[u]) { thecnt++;intv=0; + Do{ -v=st[top--]; $belone[v]=CNT; $inst[v]=0; -} while(v!=u); - } the return; - }Wuyi voidinit () { thememset (HD,0,sizeofHD); -memset (Belone,0,sizeofbelone); Wumemset (DFN,0,sizeofDFN); -memset (Inst,0,sizeofinst); AboutDtime=0, mct=0; cnt=0; $ return; - } - intK; - intMain () { Ak=read (); + while(k--){ the init (); -N=read (); m=read (); $ inti,j,x,y; the Chara[5],op; the for(i=1; i<=m;i++){ theop=GetChar (); the while(op!='m'&& op!='h') op=GetChar (); - if(op=='m') X=read () +n;Elsex=read (); inop=GetChar (); the while(op!='m'&& op!='h') op=GetChar (); the if(op=='m') Y=read () +n;Elsey=read (); About //Read the intTxif(x>n) Tx=x-n;Elsetx=x+N; the intTyif(y>n) Ty=y-n;Elsety=y+N; the Add_edge (ty,x); + Add_edge (tx,y); - } the for(i=1; i<=n*2; i++)if(!Dfn[i]) Tarjan (i);Bayi BOOLflag=0; the for(i=1; i<=n;i++){ the if(belone[i]==belone[i+N]) { -flag=1; Break; - } the } the if(flag) printf ("bad\n"); the Elseprintf"good\n"); the } - return 0; the}
Bzoj1823 [JSOI2010] Feast