Problem B
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
Input
The first line of input consists of two integers
The next
The next
It is guaranteed that at least one atom has its location fixed.
Output
Display
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 |