#C4037. Flora Clusters Connectivity

    ID: 47531 Type: Default 1000ms 256MiB

Flora Clusters Connectivity

Flora Clusters Connectivity

You are given N trees, each with a pair of coordinates, and M growth paths connecting some pairs of trees. A growth path indicates that the two trees belong to the same flora cluster. Two trees are considered to be in the same flora cluster if there is a path connecting them through one or more growth paths.

Your task is to determine, for each query, whether the two specified trees belong to the same flora cluster.

Note: Although the coordinates of the trees are provided, they do not affect the connectivity. Connectivity is solely determined by the growth paths.

The relation between two trees, say a and b, can be conceptually represented by the following equivalence condition: \[ \text{cluster}(a) = \text{cluster}(b) \iff \exists \text{ a series of growth paths connecting } a \text{ and } b. \]

inputFormat

The input is given via standard input (stdin) in the following format:

  • The first line contains two integers: N (the number of trees) and M (the number of growth paths).
  • The next N lines each contain two integers, representing the coordinates of a tree. (These values are provided for context but are not used in the connectivity analysis.)
  • The following M lines each contain two integers, indicating a growth path between two trees (tree numbers are between 1 and N).
  • The next line contains an integer P, the number of queries.
  • The next P lines each contain two integers, specifying a query to check whether the two trees belong to the same flora cluster.

outputFormat

For each query, print a single line to standard output (stdout) containing either connected or not connected, indicating whether the two trees in the query belong to the same cluster.

## sample
5 3
1 1
2 2
3 3
4 4
5 5
1 2
2 3
4 5
3
1 3
1 4
4 5
connected

not connected connected

</p>