#K76637. Festival of Paths

    ID: 34687 Type: Default 1000ms 256MiB

Festival of Paths

Festival of Paths

During the annual Festival of Paths, a mysterious network of city intersections and alleyways is unveiled. You are given a graph with n intersections and m two-way alleyways. In this network, if two intersections belong to the same connected component, then there exists a unique simple path between them. For each of the q queries, determine whether there exists such a unique path between the given intersections. Formally, for intersections \( u \) and \( v \), if \( u \) and \( v \) are in the same connected component, output \( 1 \); otherwise, output \( 0 \).

inputFormat

The first line contains two integers \( n \) and \( m \), representing the number of intersections and alleyways, respectively. Each of the next \( m \) lines contains two integers \( u \) and \( v \), indicating there is a two-way alleyway between intersections \( u \) and \( v \). The following line contains an integer \( q \), the number of queries. Each of the next \( q \) lines contains two integers \( u \) and \( v \), representing a query asking whether there exists a unique simple path between these intersections.

outputFormat

For each query, output a single line containing an integer: output 1 if there exists a unique simple path (i.e. the two intersections are in the same connected component), otherwise output 0.

## sample
6 7
1 2
2 3
3 4
4 5
5 6
2 5
3 6
3
1 6
2 4
1 5
1

1 1

</p>