Hide

Problem F
Molecules

A molecule consists of atoms that are held together by chemical bonds. Each bond links two atoms together. Each atom may be linked to multiple other atoms, each with a separate chemical bond. All atoms in a molecule are connected to each other via chemical bonds, directly or indirectly.

The chemical properties of a molecule is determined by not only how pairs of atoms are connected by chemical bonds, but also the physical locations of the atoms within the molecule. Chemical bonds can pull atoms toward each other, so it is sometimes difficult to determine the location of the atoms given the complex interactions of all the chemical bonds in a molecule.

You are given the description of a molecule. Each chemical bond connects two distinct atoms, and there is at most one bond between each pair of atoms. The coordinates of some of the atoms are known and fixed, and the remaining atoms naturally move to the locations such that each atom is at the average of the locations of the connected neighboring atoms via chemical bonds. For simplicity, the atoms in the molecule are on the Cartesian $xy$-plane.

Input

The first line of input consists of two integers $n$ ($2 \leq n \leq 100$), the number of atoms, and $m$ ($n-1 \leq m \leq \frac{n(n-1)}{2}$), the number of chemical bonds.

The next $n$ lines describe the location of the atoms. The $i^\textrm {th}$ of which contains two integers $x, y$ ($0 \leq x,y \leq 1\, 000$ or $x = y = -1$), which are the $x$ and $y$ coordinates of the $i^\textrm {th}$ atom. If both coordinates are $-1$, however, the location of this atom is not known.

The next $m$ lines describe the chemical bonds. The $i^\textrm {th}$ of which contains two integers $a$ and $b$ ($1 \leq a < b \leq n$) indicating that there is a chemical bond between atom $a$ and atom $b$.

It is guaranteed that at least one atom has its location fixed.

Output

Display $n$ lines that describe the final location of each atom. Specifically, on the $i^\textrm {th}$ such line, display two numbers $x$ and $y$, the final coordinates of the $i^\textrm {th}$ atom. If there are multiple solutions, any of them is accepted. A solution is accepted if the coordinates of each unknown atom and the average coordinates of all its neighboring atoms via chemical bonds differ by at most $10^{-3}$. Note that it is acceptable for multiple atoms to share the same coordinates.

Sample Input 1 Sample Output 1
3 2
0 0
-1 -1
2 0
1 2
2 3
0 0
1 0
2 0
Sample Input 2 Sample Output 2
5 4
0 0
-1 -1
-1 -1
-1 -1
4 0
1 2
2 3
3 4
4 5
0 0
1 0
2 0
3 0
4 0
Sample Input 3 Sample Output 3
4 3
0 0
2 0
1 1
-1 -1
1 4
2 4
3 4
0 0
2 0
1 1
1 0.3333333

Please log in to submit a solution to this problem

Log in