这个题告诉我变量循环使用,一定要赋好初值!!!!!!
一定要赋好初值!!!!!!一定要赋好初值!!!!!!一定要赋好初值!!!!!!
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int t,n,m,head[205],next[2005],v[2005],cnt,dfn[205],cnt1,low[205];
int zhan[205],zhan1[205],top,shu[205],shu1;
int du()
{
int a1;
char ch;
ch=getchar();
for(;ch!=‘m‘&&ch!=‘h‘;ch=getchar());
scanf("%d",&a1);
if(ch==‘m‘)
return a1*2;
else
return a1*2-1;
}
void jia(int a1,int a2)
{
cnt++;
next[cnt]=head[a1];
head[a1]=cnt;
v[cnt]=a2;
return;
}
void dfs(int a1)
{
cnt1++;
low[a1]=dfn[a1]=cnt1;
zhan[a1]=1;
top++;
zhan1[top]=a1;
for(int i=head[a1];i;i=next[i])
if(!dfn[v[i]])
{
dfs(v[i]);
low[a1]=min(low[a1],low[v[i]]);
}
else
if(zhan[v[i]])
low[a1]=min(low[a1],dfn[v[i]]);
if(low[a1]==dfn[a1])
{
shu1++;
for(int i=zhan1[top];i!=a1;top--,i=zhan1[top])
{
shu[i]=shu1;
zhan[i]=0;
}
top--;
shu[a1]=shu1;
zhan[a1]=0;
}
return;
}
int main()
{
scanf("%d",&t);
for(int i=0;i<t;i++)
{
memset(next,0,sizeof(next));
shu1=0;
top=0;
cnt=0;
cnt1=0;
scanf("%d %d",&n,&m);
for(int i=1;i<=2*n;i++)
head[i]=dfn[i]=0;
for(int j=0;j<m;j++)
{
int a1,a2,b1,b2;
a1=du();
b1=du();
if(a1%2==0)
a2=a1-1;
else
a2=a1+1;
if(b1%2==0)
b2=b1-1;
else
b2=b1+1;
jia(a2,b1);
jia(b2,a1);
}
for(int i=1;i<=2*n;i++)
if(dfn[i]==0)
dfs(i);
int kg=1;
for(int i=1;i<=n;i++)
if(shu[i*2]==shu[i*2-1])
{
kg=0;
printf("BAD\n");
break;
}
if(kg)
printf("GOOD\n");
}
return 0;
}