Logo
(追記) (追記ここまで)

32503번 - Genetic Reconstruction 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB43101062.500%

문제

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 2020 English lowercase letters (from ‘a’ to ‘t’).

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.

입력

The first line of input contains a single integer $n$ (1ドル≤n≤20$), which is the number of creatures in your study. The creatures are numbered from 1ドル$ to $n$.

Each of the next $n$ lines contains two integers $p_1,ドル $p_2$ ((1ドル≤p_1,p_2≤n,ドル $p_1 \ne p_2$) or $p_1=p_2=0$) and a character $c$ ($c \in${‘a’, $\dots,ドル ‘t’}), where $p_1$ and $p_2$ represent the parents of the given creature (or are both 0ドル$ if the parents are unknown), and $c$ is the given creature’s eye color. Note that either both parents will be known or both will be unknown, and that both parents’ numbers will be less than the number of the given creature; no creature can be its own ancestor or descendant.

출력

If the information is consistent, output the alleles for each creature one per line, with no spaces; otherwise output $-1$. If there are multiple possible solutions, output only the one that comes first alphabetically (e.g., the alphabetically first allele pair for first creature, then second, and so on).

제한

예제 입력 1

3
0 0 a
0 0 b
1 2 c

예제 출력 1

ac
bc
cc

예제 입력 2

3
0 0 c
0 0 c
2 1 a

예제 출력 2

-1

힌트

출처

ICPC > Regionals > North America > North America Qualification Contest > ICPC North America Qualifier 2024 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /