NiveusNix @ 2019-07-24 16:25:33
请问这道题char和int循环读入有问题吗?
#include<bits/stdc++.h>
using namespace std;
#define N 100100
int V,E,u,v,T;
struct node{
int degree;
vector <int> edge;
}d[N];
bool vis[N];
int Stark[N],top;
int dfn[N],t;
int low[N];
int color[N],hue;
int tot[N];
void Tanjar(int u){
dfn[u]=++t;
low[u]=t;
vis[u]=true;
Stark[++top]=u;
for(int i=0;i<d[u].degree;i++){
v=d[u].edge[i];
if(dfn[v]==false){
Tanjar(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]==true){
low[u]=min(low[u],low[v]);
}
}
if(dfn[u]==low[u]){
color[u]=++hue;
vis[u]=false;
while(Stark[top]!=u){
color[Stark[top]]=hue;
vis[Stark[top--]]=false;
}
top--;
}
}
char ch1,ch2;
int main(){
cin>>T;
// T=1;
while(T--){
memset(d,0,sizeof(d));
memset(vis,0,sizeof(vis));
memset(Stark,0,sizeof(Stark));
memset(dfn,0,sizeof(dfn));
memset(low,0,sizeof(low));
memset(color,0,sizeof(color));
memset(tot,0,sizeof(tot));
cin>>V>>E;
for(int i=1;i<=E;i++){
cin>>ch1>>u>>ch2>>v;
if(ch1=='h'&&ch2=='h'){
d[u+V].edge.push_back(v);
d[u+V].degree+=1;
d[v+V].edge.push_back(u);
d[v+V].degree+=1;
}
if(ch1=='h'&&ch2=='m'){
d[u+V].edge.push_back(v+V);
d[u+V].degree+=1;
d[v].edge.push_back(u);
d[v].degree+=1;
}
if(ch1=='m'&&ch2=='h'){
d[u].edge.push_back(v);
d[u].degree+=1;
d[v+V].edge.push_back(u+V);
d[v+V].degree+=1;
}
if(ch1=='m'&&ch2=='m'){
d[u].edge.push_back(v+V);
d[u].degree+=1;
d[v].edge.push_back(u+V);
d[v].degree+=1;
}
}
V+=V;
for(int i=1;i<=V;i++){
if(dfn[i]==false){
Tanjar(i);
}
}
bool pd=0;
for(int i=1;i<=V/2;i++){
if(color[i]==color[i+V/2]){
cout<<"BAD"<<endl;
pd=1;
break;
}
}
if(pd==0){
cout<<"GOOD"<<endl;
}
}
}