将辈分差距转为数字
例如 A 是 B son
A=B-1
A 是 B grandfather
A=B+2
然后编号1数字设置为0,建图bfs
最后搜索编号2到100是否存在>0的数即可
#include v[]; }
using namespace std;
typedef pair
vector
queue
int dis[];
bool vis[];
int main(){
memset(dis,0x3f,sizeof dis);
int N,i,now,cnt,a,b;
char s[];
scanf("%d",&N);
while(N--){
scanf("%d is %d's %s",&a,&b,s);
if(strcmp(s,"father.")==){
v[a].push_back(P(b,-));
v[b].push_back(P(a,));
}
else if(strcmp(s,"son.")==){
v[a].push_back(P(b,));
v[b].push_back(P(a,-));
}
else if(strcmp(s,"brother.")==){
v[a].push_back(P(b,));
v[b].push_back(P(a,));
}
else if(strcmp(s,"grandson.")==){
v[a].push_back(P(b,));
v[b].push_back(P(a,-));
}
else if(strcmp(s,"grandfather.")==){
v[a].push_back(P(b,-));
v[b].push_back(P(a,));
}
}
vis[]=true;
dis[]=;
q.push();
while(!q.empty()){
now=q.front();
q.pop();
cnt=v[now].size();
for(i=;i
flag=false;
break;
}
puts(flag?"2333333…":"ku jiu ru hou xin zuo tong.");return ;
手机扫一扫
移动阅读更方便
你可能感兴趣的文章