아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Family

면접 대비

시간 제한1초메모리 제한1024 MB

요약
사람들 사이의 가족 관계가 주어질 때, 각 질의 쌍이 서로 연결되어 있는지 판별한다.
난이도

보통10점 중 5점

유형
그래프, 유니온 파인드
정답자
아직 제출이 없습니다

문제

You have been given bits and pieces of your family tree. Your task is to determine if two people are related based on several connections.

입력

The first line will contain a single integer n that indicates the number of connections. The next n lines will consist of a name, a connection, and another name. The connections will be either mom, dad, brother, sister, daughter, or son. The next line will contain a single integer m that indicates the number of test cases. The next m lines will consist of two names. Your program should determine if the two names are related.

출력

Output either Related or Not Related, depending on whether they are connected or not. There will be m lines of output.

예제1

  1. 예제 1

    입력
    3
    John brother Susan
    Kim mom John
    Dave son Jim
    2
    Jim John
    Kim Susan
    
    예상 출력
    Not Related
    Related