-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.cpp
More file actions
66 lines (59 loc) · 1.06 KB
/
Tree.cpp
File metadata and controls
66 lines (59 loc) · 1.06 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
#include <bits/stdc++.h>
#define _ 0
using namespace std;
struct Node {
Node* left;
Node* right;
int data;
Node (int data) {
this->data = data;
this->right = this->left = NULL;
}
};
bool isLeaf(Node* node) {
return (node != NULL && node->right == NULL && node->left == NULL);
}
void build(int n, Node* &root) {
map<int, Node*> mp;
int u, v; char c;
for (int i = 0; i < n; ++i) {
cin >> u >> v >> c;
if (mp.find(u) == mp.end()) {
mp[u] = new Node(u);
if (root == NULL) {
root = mp[u];
}
}
Node *p = mp[u];
mp[v] = new Node(v);
if (c == 'L') {
p->left = mp[v];
}
else {
p->right = mp[v];
}
}
}
bool isfull(Node* root) {
if (root == NULL) return false;
if (root->left == NULL && root->right == NULL) return true;
if ((root->left) && (root->right)) {
return (isfull(root->left) && isfull(root->right));
}
return false;
}
int main() {
int T; cin >> T;
while (T--) {
int n; cin >> n;
Node* root = NULL;
build(n, root);
if (isfull(root)) {
cout << "1\n";
}
else {
cout << "0\n";
}
}
return (0^_^0);
}