-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5t_P332.cpp
87 lines (73 loc) · 1.49 KB
/
5t_P332.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
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
84
85
86
87
#include <iostream>
#include <cstdio>
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define endl "\n"
#define cy cout << "YES" << "\n"
#define cn cout << "NO" << "\n"
#define cnl cout << "\n"
#define DEBUG_(t) cout << "###DEBUG:" << t << endl
#define mset(a) memset(a, 0, sizeof(a))
#define PII pair<int, int>
using namespace std;
const int MAXN = 100000 + 5;
struct Node
{
int data;
Node* left;
Node* right;
Node(int t) : data(t), left(NULL), right(NULL) {};
};
vector<int> vi;
Node* Nodes[10010];
void inOrder(Node* root)
{
if(root != NULL)
{
inOrder(root->left);
vi.push_back(root->data);
inOrder(root->right);
}
}
int a[10010][3];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int rootIndex;
cin >> rootIndex;
for(int i = 1; i <= n; i++)
{
cin >> a[i][0] >> a[i][1] >> a[i][2];
Nodes[i] = new Node(a[i][0]);
}
for(int i = 1; i <= n; i++)
{
if(a[i][1] != 0)
{
Nodes[i]->left = Nodes[a[i][1]];
}
if(a[i][2] != 0)
{
Nodes[i]->right = Nodes[a[i][2]];
}
}
Node* root = Nodes[rootIndex];
inOrder(root);
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
if(vi[j] < vi[i])
{
cout << "false";
return 0;
}
}
}
cout << "true";
return 0;
}