P2307 Maze

Background

None.

Description

Xiaoxi loves playing maze games, and now she has designed one herself. In her design, all corridors are bidirectionally connected: if a corridor connects rooms A and B, you can go from room A to room B through it, and also from room B to room A. To increase the difficulty, Xiaoxi wants there to be exactly one path between any two rooms (unless you retrace your steps). She gives you her blueprint and asks you to determine whether it matches her idea. For example, if there are two different ways to go from $5$ to $8$, then it does not satisfy the requirement.

Input Format

The input contains multiple test cases. Each test case is a list of integer pairs ending with `0 0`, where each pair indicates a corridor connecting two rooms. Room IDs are at least $1$ and at most $100000$. There is one blank line between any two test cases. The entire input ends with `-1 -1`.

Output Format

For each test case, output exactly one line. If the maze conforms to Xiaoxi’s idea, output `1`; otherwise, output `0`.

Explanation/Hint

None. Translated by ChatGPT 5