# bzoj1823 [JSOI2010]满汉全席

http://www.elijahqi.win/archives/3094
Description

Input

Output

Sample Input

2
3 4
m3 h1
m1 m2
h1 h3
h3 m2
2 4
h1 m2
m2 m1
h1 h2
m1 h2

Sample Output

GOOD

HINT

Source

JSOI2010第二轮Contest2

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=440;
const int M=2200;
inline char gc(){
static char now[1<<16],*S,*T;
return *S++;
}
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
struct node{
int y,next;
}data[M];bool stackf[N];
int h[N],q[N],dfn[N],low[N],top,n,T,m,id[N][2],cnt,num,s,b[N];
inline void insert1(int x,int y){
data[++num].y=y;data[num].next=h[x];h[x]=num;
}
inline void tarjan(int x){
dfn[x]=low[x]=++num;stackf[x]=1;q[++top]=x;
for (int i=h[x];i;i=data[i].next){
int y=data[i].y;
if (!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]);else if (stackf[y]) low[x]=min(low[x],dfn[y]);
}
if (dfn[x]==low[x]){
++s;int y;
do{
y=q[top--];stackf[y]=0;b[y]=s;
}while(y!=x);
}
}
int main(){
freopen("bzoj1823.in","r",stdin);
while(T--){
for (int i=0;i<n;++i) id[i][0]=++cnt,id[i][1]=++cnt;//0->h 1->m;
for (int i=1;i<=m;++i){int x,x1,t1,t2;char ch=gc();
while(ch!='h'&&ch!='m') ch=gc();
}