#C1963. Matching Constellations
Matching Constellations
Matching Constellations
You are given a set of known constellations and several query constellations. Each constellation is represented by a list of stars with integer coordinates.
Two constellations are considered identical if the multiset (order does not matter) of the squared Euclidean distances between every pair of stars are the same. The squared distance between two stars located at \( (x_1, y_1) \) and \( (x_2, y_2) \) is defined as:
[ d^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2 ]
Your task is to determine, for each query constellation, whether it matches any of the known constellations. If a match is found, output the 1-indexed position of that constellation; otherwise, output \(-1\). Note that the comparison is invariant under translations since only the squared distances matter.
inputFormat
The input is given via standard input (stdin) and consists of the following:
- An integer \( m \) representing the number of known constellations.
- For each of the \( m \) known constellations:
- An integer \( s \) representing the number of stars in the constellation.
- \( s \) pairs of integers, where each pair represents the \( x \) and \( y \) coordinates of a star.
- An integer \( q \) representing the number of query constellations.
- For each query, exactly \( s_0 \) pairs of integers are provided, where \( s_0 \) is the number of stars in the first known constellation.
All numbers are separated by whitespace.
outputFormat
For each query constellation, output an integer on a separate line indicating the 1-indexed number of the matching known constellation. If no match is found, output \(-1\).
## sample2
4
0 0
1 0
1 1
0 1
4
0 0
2 0
2 2
0 2
2
1 1
2 1
2 2
1 2
1 1
3 1
3 3
1 3
1
2
</p>