Universal Cup Judging System

Universal Cup

Süre Sınırı: 3 s Bellek Sınırı: 1024 MB Toplam puan: 100
İstatistikler

Captain Jack は $n$ 個の島を占領している。彼はこの $n$ 個の島に王国を築きたい。各島には添字 $i$($1\le i\le n$)を名前として付ける。最初はどの二つの島の間にも橋がなかった。しかし、Jack は任意の二つの島 $p$ と $q$ を車で視察したい。島 $p$ から島 $q$ に行けないとき、Jack は島 $p$ と $q$ の間に橋を建設する。二つの島の添字 $p$ と $q$ が与えられたとき、Jack が $p$ から $q$ に移動できるかを調べるプログラムを書いてほしい。例えば、最初に Jack は島 $2$ から島 $3$ に行きたいが、その間に橋はない。そのため、車で島 $2$ から島 $3$ に移動できず、プログラムは "N" を出力しなければならない。その後、Jack は島 $2$ と島 $3$ の間に橋を建設することにする。次に Jack は島 $3$ から島 $4$ に行きたいが、島 $4$ と、島 $3$ に連結している他の島を結ぶ橋はまだない。したがって、プログラムは "N" を出力しなければならない。次に Jack が島 $2$ から島 $4$ に行きたい場合、島 $2$ と $3$ の間、および島 $3$ と $4$ の間に橋があるため、プログラムは "Y" を出力する。表2にこの過程の例を示す。

表2:連結性の例

入力 $p\ q$ 出力 以前の組から $p$ と $q$ の連結が分かる理由
$2\ 3$ N 島 $2$ と島 $3$ の間に橋を建設する。
$3\ 4$ N 島 $3$ と島 $4$ の間に橋を建設する。
$2\ 4$ Y 島 $2$ と $3$ の間に橋があり、島 $3$ と $4$ の間にも橋がある。

入力

入力の最初の行は整数 $n$($1\le n\le10000$)で、Jack が二つの島の間を移動する回数を表す。続く $n$ 行には空白で区切られた二つの整数 $p$ と $q$ が含まれ、Jack が島 $p$ から島 $q$ に移動したいことを示す($0\le p,q<1000$)。

制約

  • $1\le n\le10000$

  • $0\le p,q<1000$; $p\ne q$.

出力

各テストケースについて、Jack が島 $p$ から島 $q$ に移動できるかどうかを表す "Y" または "N" を含む行を一行出力せよ。

入出力例

入力 1

12
3 4
4 9
8 1
2 3
5 6
2 9
5 9
7 3
4 8
5 6
1 8
6 1

出力 1

N
N
N
N
N
Y
N
N
N
Y
Y
Y

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.