Problem H
Genetic Reconstruction
You’re in charge of studying a new species, and you’d like to make sure the work that you’ve collected is correct.
There are several creatures. For each one, you know the eye
color they have. This is denoted by one of the first
You think that there is a gene that controls eye color. Your hypothesis is that each creature has two Alleles. An allele is represented by a lowercase English letter. The resulting eye color of the creature is the allele of the two which comes first alphabetically.
In addition, you’ve identified two parents of each creature. Some parents’ information may be missing; either both parents’ information will be available or both will be missing. A creature inherits one allele from each parent; any of the four combinations is possible. For example, one parent with alleles ‘ak’ (thus eye color ‘a’), and another with alleles ‘em’ (eye color ‘e’), might have a child with alleles ‘ae’ (eye color ‘a’), ‘am’ (eye color ‘a’), ‘ek’ (eye color ‘e’) or ‘km’ (eye color ‘k’).
Given the number of creatures, the parent information, and the eye color of each creature, determine if this information is consistent with your hypothesis.
Input
The first line of input contains a single integer
Each of the next
Output
If the information is consistent, output the alleles for
each creature one per line, with no spaces; otherwise output
Sample Input 1 | Sample Output 1 |
---|---|
3 0 0 a 0 0 b 1 2 c |
ac bc cc |
Sample Input 2 | Sample Output 2 |
---|---|
3 0 0 c 0 0 c 2 1 a |
-1 |