SKY_magician @ 2018-05-16 18:13:36
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int low[110000],dfn[110000],ist[110000],belong[110000],cnt,tot;
vector<int>v[11000];
stack<int>a;
void tarjan(int x){
dfn[x]=low[x]=++cnt;
a.push(x);
ist[x]=1;
int i,j,k;
for(i=0;i<v[x].size();i++)
if(!dfn[v[x][i]]){
tarjan(v[x][i]);
low[x]=min(low[v[x][i]],low[x]);
}else if(ist[v[x][i]]){
low[x]=min(low[x],dfn[v[x][i]]);
}
if(dfn[x]==low[x]){
tot++;
while(1){
int u=a.top();
a.pop();
ist[u]=0;
belong[u]=tot;
if(u==x)break;
}
}
}
int main()
{ int n,m,i,j,k,t;
cin>>t;
while(t--){
cnt=0;
tot=0;
memset(low,0,sizeof(low));
memset(dfn,0,sizeof(dfn));
memset(ist,0,sizeof(ist));
memset(belong,0,sizeof(belong));
while(!a.empty())a.pop();
cin>>n>>m;
for(i=1;i<=m;i++){
string s,t;
cin>>s>>t;
int x=0,y=0,xx=0,yy=0;
int n1=s.length(),n2=t.length();
if(s[0]=='m')x=n;
for(j=1;j<n1;j++)
xx=xx*10+(s[j]-'0');
x+=xx;
if(t[0]=='m')y=n;
for(j=1;j<n2;j++)
yy=yy*10+(t[j]-'0');
y+=yy;
if(y>n){
v[x].push_back(y-n);
}else v[x].push_back(y+n);
if(x>n){
v[y].push_back(x-n);
}else v[y].push_back(x+n);
}
for(i=1;i<=2*n;i++)
if(!dfn[i])
tarjan(i);
int ok=1;
for(i=1;i<=n;i++)
if(belong[i]==belong[i+n]){
puts("BAD");
ok=0;
break;
}
if(ok)puts("GOOD");
}
return 0;
}
by SKY_magician @ 2018-05-16 18:19:27
已过