-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00939 Genes.cpp
55 lines (53 loc) · 1.3 KB
/
00939 Genes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mss map <string, string>
#define msvs map <string, vector<string>>
using namespace std;
void getGenes(mss& tipo, msvs& pai, string& son){
if(!tipo.count(son)){
string first = pai[son][0];
string second = pai[son][1];
getGenes(tipo,pai,first);
getGenes(tipo,pai,second);
first = tipo[first];
second = tipo[second];
if((first=="dominant" && (second!="non-existent")) ||
(second=="dominant" && (first!="non-existent"))){
tipo[son] = "dominant";
}else if((first=="dominant" || second=="dominant") ||
(first!="non-existent" && second!="non-existent")){
tipo[son] = "recessive";
}else tipo[son] = "non-existent";
}
}
int main(){
int n;
scanf("%d", &n);
string first, second;
vector <string> undone;
mss tipo;
msvs pai;
while(n--){
cin >> first >> second;
if(second == "dominant" || second == "recessive" || second == "non-existent"){
tipo[first] = second;
}
else{
pai[second].pb(first);
undone.pb(second);
}
}
for(int i=0, sz=undone.size();i<sz;i++){
if(tipo.count(undone[i])) continue;
getGenes(tipo,pai,undone[i]);
}
for(auto it=tipo.begin();it!=tipo.end();it++){
cout << it->first << " " << it->second << endl;
}
return 0;
}