-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj1217.cpp
More file actions
83 lines (81 loc) · 1.69 KB
/
aoj1217.cpp
File metadata and controls
83 lines (81 loc) · 1.69 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool des(string a, string b, map<string, string> &m) {
string s = a;
while(s != "") {
if(s == b)
return true;;
s = m[s];
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
while(cin >> n >> m, n|m) {
cin.ignore();
vector<string> v(1000);
map<string, string> ma;
REP(i, n) {
string s;
getline(cin, s);
int cnt = 0;
while(s[cnt] == ' ')
cnt++;
s = s.substr(cnt);
ma[s] = cnt ? v[cnt-1] : "";
v[cnt] = s;
}
REP(i, m) {
string in1, in2, in3;
cin >> in1;
cin >> in2 >> in2 >> in2;
cin >> in3 >> in3;
in3.erase(in3.end() - 1);
bool ans = false;
if(in2 == "child" && ma[in1] == in3)
ans = true;
else if(in2 == "parent" && ma[in3] == in1)
ans = true;
else if(in2 == "sibling" && ma[in1] == ma[in3])
ans = true;
else if(in2 == "descendant")
ans = des(in1, in3, ma);
else if(in2 == "ancestor")
ans = des(in3, in1, ma);
cout << (ans ? "True" : "False") << endl;
}
cout << endl;
}
return 0;
}