#P5884. [IOI 2014] game 游戏

[IOI 2014] game 游戏

Description

Jianjia is a boy who likes playing games. When someone asks him a question, he prefers to answer by playing a game instead of answering directly. Jianjia met his friend Meiyu and told her about Taiwan’s airline network. In Taiwan there are nn cities (numbered 0,,n10,\cdots,n−1), and there are air routes between some pairs of cities. Each route connects two cities and is bidirectional.

Meiyu asked Jianjia whether it is possible to travel by plane between any two cities (directly or indirectly). Jianjia does not want to answer directly, and instead wants to tell her through a game. Meiyu may ask, “Is there a direct air route between cities uu and vv?”, and Jianjia must answer immediately. Meiyu will ask about each pair of cities exactly once, so in total there will be r=n(n1)2r = \frac{n (n−1)}{2} questions. If from the answers to the first ii questions (i<ri<r) it is already possible to determine whether the whole airline network is connected, that is, whether it is possible to travel between any pair of cities by plane (directly or indirectly), then Meiyu wins. Otherwise, this means she needs to know all rr answers, and then Jianjia wins.

To make the game more fun, they agreed that Jianjia does not have to follow the real airline network in Taiwan. Instead, he may make up the airline network as the game progresses, that is, he can decide how to answer later based on Meiyu’s previous questions. Your task is to help him win the game by deciding how Jianjia should answer.

Input Format

  • Line 11: A positive integer nn, the number of cities.
  • The remaining rr lines: Each line contains two integers uu and vv, representing a question about cities uu and vv.

Output Format

  • Output rr lines. For each question from Meiyu, you must answer whether there is a direct air route between cities vv and uu. Specifically, output 11 if there is, and 00 if there is not.
4
0 3
1 0
0 2
3 1
1 2
2 3

0
1
0
1
0
1

Hint

Subtasks and Constraints

Subtask Score nn
11 1515 n=4n=4
22 2727 4n804 \le n \le 80
33 5858 4n15004 \le n \le 1500

Translated by ChatGPT 5