Game
Time limit1sMemory limit512 MB
Given the pair query order, the program prints the smallest 0/1 answer string that keeps connectivity undecided until the last query.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Game theory
- Solved
- No attempts yet
Problem
Jian-Jia is a boy who loves games. When someone asks him a question, he would rather turn it into a game than answer right away. Jian-Jia told his friend Mei-Yu about the flight network of Taiwan. There are cities, numbered through . Some pairs of cities are joined by a direct flight, and a flight can be taken in both directions.
Mei-Yu wanted to know whether she can travel between any two cities by plane, either directly or with stopovers. Instead of telling her, Jian-Jia proposed a game. Mei-Yu asks questions of the form "are city and city joined by a direct flight?", and Jian-Jia answers yes or no immediately. Mei-Yu asks about every pair of cities exactly once, so there are questions in total.
Mei-Yu wins if there is some such that the first answers already settle whether travel between every pair of cities is possible. If she instead needs all answers, Jian-Jia wins.
To make the game more fun, the two agreed that Jian-Jia may forget the real flight network. He invents it as the questions arrive, and the only thing he must respect is his own earlier answers. A flight network agrees with the first answers when every pair answered yes is joined by a direct flight and every pair answered no is not. A pair that has not been asked yet may be joined or not. As long as two networks agree with the first answers, one of them connecting all cities and the other one not, Mei-Yu has settled nothing.
You are given the order in which Mei-Yu asks. Find the lexicographically smallest sequence of answers with which Jian-Jia wins, writing no as and yes as , where comes before . For a winning sequence always exists.
Input
The first line contains the number of cities .
Each of the next lines contains one question, in the order Mei-Yu asks. A line holds two different integers and separated by a space, which is the question of whether city and city are joined by a direct flight. Ignoring the order inside a pair, every pair appears exactly once in the input.
Output
Print one line with a string of length . Its -th character is Jian-Jia's answer to the -th question, written as for no and for yes. If several strings let Jian-Jia win, print the lexicographically smallest one.
Constraints
- , ,