Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- using namespace std;
- vector < vector < int > > arr;
- bool dfs(vector < vector < int > > &arr, int pos, int left, int right)
- {
- if (pos < 0)
- {
- return true;
- }
- if (arr[pos][0] >= right || arr[pos][0] <= left)
- {
- return false;
- }
- return (dfs(arr, arr[pos][1], left, arr[pos][0]) && dfs(arr, arr[pos][2], arr[pos][0], right));
- }
- int main()
- {
- ifstream fin("check.in");
- ofstream fout("check.out");
- int n;
- fin >> n;
- arr.resize(n);
- int key, num1, num2;
- if (n == 0)
- {
- fout << "YES";
- } else {
- for (int i = 0; i < n; i++)
- {
- fin >> key >> num1 >> num2;
- arr[i].push_back(key);
- arr[i].push_back(num1 - 1);
- arr[i].push_back(num2 - 1);
- }
- if (dfs(arr, 0, INT32_MIN, INT32_MAX))
- {
- fout << "YES";
- } else {
- fout << "NO";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement