-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckisitbst.cpp
More file actions
50 lines (42 loc) · 829 Bytes
/
Copy pathcheckisitbst.cpp
File metadata and controls
50 lines (42 loc) · 829 Bytes
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
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;
vector<lli> leftchild,rightchild;
vector<lli> key,v;
void inOrder(lli root)
{
if(root==-1)
return;
inOrder(leftchild[root]);
if(root!=-1)
v.pb(key[root]);
inOrder(rightchild[root]);
}
int main()
{
fastio;
lli n,i,f=0;
cin>>n;
key.resize(n);
leftchild.resize(n+5,-1);
rightchild.resize(n+5,-1);
for(i=0;i<n;i++)
cin>>key[i]>>leftchild[i]>>rightchild[i];
if(n>1)
{
inOrder(0); // left,right,root
for(i=1;i<v.size();i++)
if(v[i]<=v[i-1])
f=1;
}
if(f)
cout<<"INCORRECT";
else
cout<<"CORRECT";
}