1823: [JSOI2010] Feast time limit:10 Sec Memory limit:64 MB 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
HINT Source
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;#defineM 100010#defineN 210inlineintMinintAintb) {returnA<b?a:b;} InlineintRead () {intx=0, f=1;CharCh=GetChar (); 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;}int Get(){ intx; CharC=GetChar (); while(c!='m'&&c!='h') c=GetChar (); if(c=='m') X=read () *2; ElseX=read () *2-1; returnx;}structljn{intFro,to;} E[M];intN,m,t,t1,t2,lj[n],cnt,qwe,dfn[n],low[n],q[n],tq,num[n],tot;BOOLVs[n];inlinevoidAddintAintb) {cnt++;e[cnt].fro=lj[a];e[cnt].to=b;lj[a]=CNT;}voidTarjan (intx) {Vs[x]=1; q[++tq]=x; DFN[X]=low[x]=++qwe; for(intI=lj[x];i;i=E[i].fro) { intet=e[i].to; if(!Dfn[et]) {Tarjan (ET); LOW[X]=min (Low[x],low[et]); } Else if(Vs[et]) low[x]=min (Low[x],dfn[et]); } if(dfn[x]==Low[x]) {Tot++; intnow=0; while(now!=x) {now=q[tq--];num[now]=tot;vs[now]=0;} }}intMain () {T=read (); while(t--) {memset (DFN,0,sizeof(DFN)); memset (Low,0,sizeof(low)); memset (VS,0,sizeof(VS)); memset (LJ,0,sizeof(LJ)); memset (num,0,sizeof(num)); N=read (); m=read (); intX,y,xp,yp; for(intI=0; i<m;i++) {x=Get(); y=Get(); if(%2==0) xp=x--; Elsexp=x++; if(y%2==0) yp=y--; Elseyp=y++; Add (xp,y); add (yp,x); } tot=tq=qwe=0; for(intI=1; i<=n*2; i++)if(!Dfn[i]) {Tarjan (i);} BOOLf=1; for(intI=1; i<=n;i++) if(num[i*2]==num[i*2-1]) {f=0; Break;} if(f) Puts ("Good");ElsePuts" Bad"); }}
Bzoj 1823: [JSOI2010] Feast--2-sat