http://acm.pku.edu.cn/JudgeOnline/problem?id=3217
/*********************************************
http://acm.pku.edu.cn/JudgeOnline/problem?id=3217
邻接距阵:
其中 insert()函数是构造邻接距阵;
find()函数是遍历距阵节点;
**********************************************/
#include<stdio.h>
#include<memory.h>
#include<iostream>
using namespace std;
#define MAX 101
int n;
struct CON{//节点的父或子节点保存的信息;
int pos;
CON *g;
};
struct NODE{
int sex;
int d1,d2;
CON *p,*son;//此节点的父节点以及子节点;
}a[MAX];
int ans;
int rec[MAX];
int c1,c2;
void Insert(int num,int con){
CON *h=new CON;
if(a[num].son==NULL){
h->pos=con;
h->g=NULL;
a[num].son=h;
}
else{
h->pos=con;
h->g=a[num].son;
a[num].son=h;
CON *g = a[num].son;
if(num==19){
while(g){
g=g->g;
}
}
}
CON *t = new CON;
if(a[con].p==NULL){
t->pos=num;
t->g=NULL;
a[con].p=t;
}
else{
t->pos=num;
t->g=a[con].p;
a[con].p=t;
}
}
int Find1(int t){
CON *h = a[t].p;
int k;
rec[t]=1;
/*********
/* 遍历父亲节点;
*/
while(h){
k=h->pos;
a[k].d1=a[t].d1+1;
Find1(k);
h = h->g;
}
//遍历儿子节点;
/*
CON *g = a[t].son;
int j;
while(g){
j=h->pos;
a[j].d1=a[t].d1+1;
Find1(k);
h=h->g;
}*/
return 0;
}
int Find2(int t){
CON *h = a[t].p;
int k;
rec[t]=1;
while(h){
k=h->pos;
a[k].d2=a[t].d2+1;
Find2(k);
h = h->g;
}
return 0;
}
int main(){
int num;
int con,i;
NODE gg;
gg.p=gg.son=NULL;
gg.sex=1;
gg.d1=gg.d2=1000;
for(i=1;i<=100;i++){
a[i]=gg;
}
scanf("%d%d",&c1,&c2);
while(scanf("%d",&num)!=EOF){
while(scanf("%d",&con)&&con!=0&&con!=-1){
Insert(num,con);
}
a[num].sex=con;
}
if(a[c1].sex==a[c2].sex){
printf("same\n");
}
else{
a[c1].d1=0;
Find1(c1);
a[c2].d2=0;
Find2(c2);
ans=0;
for(i=1;i<=100;i++){
if(a[i].d1<3&&a[i].d2<3){
ans=1;
break;
}
}
if(ans){
printf("close\n");
}
else{
printf("marriage\n");
}
}
return 0;
}