Water supply
The city is composed of n
districts, each equipped with a well for water extraction. Every pair of wells is connected by a pipe, allowing water to flow in only one direction. Due to an energy crisis, only one well can be operational at any given time. This system, not originally designed for such a scenario, sometimes leaves certain districts without water.
Your task is to determine if it's possible to ensure an uninterrupted water supply throughout the city by reversing the direction of water flow in all pipes connected to just one well.
Input
The first line contains the number of districts n
(1 ≤ n ≤ 100) in the city. The following n
lines describe each well, listing the number of wells from which it receives water, followed by the specific well numbers. Wells are numbered from 1 to n
.
Output
Output a single number: 1 if it is possible to achieve an uninterrupted water supply, or 0 if it is not.