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

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

Asking for Money

면접 대비

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

요약
N명이 각각 한 번만 요청을 받으면 미리 정해진 두 사람에게 1달러를 요구할 때, 어떤 순서로 요청이 진행되면 손해를 볼 수 있는 사람을 모두 찾는다.
난이도

보통10점 중 7점

유형
그래프, DFS, 구현, 그리디
정답자
아직 제출이 없습니다

문제

The International Commission for the Prevention of Cons is studying the possible effects of a pyramid scheme in a town. The scheme is as follows: someone asks a person for \1$ and tells them to ask two other people for \\1 each and to tell each of them to ask for money from two others just as they are doing. In this way, the victim thinks that they are going to earn \\$$1. As there is a finite number of people in the world, not everyone can earn money this way, this is a con.

The NN people in town are susceptible to the con, that is, they are willing to give \$$1$ and later ask for money from two other people. However, they are willing to participate only once, that is, if they are asked for money again they will not give it or ask anyone. Once a person is asked for money, they give it immediately but can take some time before asking the other two people. The con starts with someone from outside the town asking someone in the town for money. This triggers a sequence of requests for money within the town.

For example, in the picture below we depict a town with five people. An arrow from AA to BB indicates that AA would ask BB for the money.

In this example, BB can lose money. We can check that with the following scenario.

  1. Someone from outside the town asks AA for money.
  2. AA asks BB for money.
  3. AA asks CC for money.
  4. CC asks DD for money.
  5. BB asks CC for money.
  6. BB asks DD for money.

Observe that when BB asks CC and DD for money, they will not give it to BB since they have already given money to someone else.

For each person in the town you know whom they are going to ask for money. Your task is to determine who in the town can lose money.

입력

The first line contains an integer NN (3≤N≤10003 ≤ N ≤ 1000) indicating the number of people in the town. Each person is identified by a distinct integer from 11 to NN. For i=1,2,…,Ni = 1, 2, \dots , N, the ii-th of the next NN lines contains two integers X_iX\_i and Y_iY\_i (1≤X_i,Y_i≤N1 ≤ X\_i , Y\_i ≤ N, X_i,Y_i≠iX\_i , Y\_i \ne i and X_i≠Y_iX\_i \ne Y\_i), representing that person ii would ask for money to person X_iX\_i and person Y_iY\_i.

출력

Output a single line with a string of length NN such that its ii-th character is the uppercase letter “Y” if person ii can lose money, and the uppercase letter “N” otherwise.

예제2

  1. 예제 1

    입력
    5
    2 3
    3 4
    4 5
    5 1
    1 2
    
    예상 출력
    YYYYY
    
  2. 예제 2

    입력
    4
    2 3
    3 4
    2 4
    2 3
    
    예상 출력
    NYYY