Logo
(追記) (追記ここまで)

28040번 - Asking for Money 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 1024 MB167666141.497%

문제

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 $N$ 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 $A$ to $B$ indicates that $A$ would ask $B$ for the money.

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

  1. Someone from outside the town asks $A$ for money.
  2. $A$ asks $B$ for money.
  3. $A$ asks $C$ for money.
  4. $C$ asks $D$ for money.
  5. $B$ asks $C$ for money.
  6. $B$ asks $D$ for money.

Observe that when $B$ asks $C$ and $D$ for money, they will not give it to $B$ 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 $N$ (3ドル ≤ N ≤ 1000$) indicating the number of people in the town. Each person is identified by a distinct integer from 1ドル$ to $N$. For $i = 1, 2, \dots , N,ドル the $i$-th of the next $N$ lines contains two integers $X_i$ and $Y_i$ (1ドル ≤ X_i , Y_i ≤ N,ドル $X_i , Y_i \ne i$ and $X_i \ne Y_i$), representing that person $i$ would ask for money to person $X_i$ and person $Y_i$.

출력

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

제한

예제 입력 1

5
2 3
3 4
4 5
5 1
1 2

예제 출력 1

YYYYY

예제 입력 2

4
2 3
3 4
2 4
2 3

예제 출력 2

NYYY

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2022 A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /