Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- using namespace std;
- struct tree{
- int m;
- int LeftChild;
- int RightChild;
- };
- bool TreeorNot(vector<tree> &array, int node) {
- if (node < 0) {
- return true;
- } else {
- if ((node <= array[node].LeftChild) || (node >= array[node].RightChild)) {
- return false;
- } else {
- return (array, array[node].LeftChild)&&(array, array[node].RightChild);
- }
- }
- }
- int main() {
- ifstream cin("check.in");
- ofstream cout("check.out");
- int n;
- int node = 0;
- cin >> n;
- vector<tree> array(n);
- if (n == 0) {
- cout << "YES";
- } else {
- for (int i = 0; i < n; ++i) {
- cin >> array[i].m >> array[i].LeftChild >> array[i].RightChild;
- --array[i].LeftChild;
- --array[i].RightChild;
- }
- }
- if (TreeorNot(array, node)){
- cout << "YES";
- } else {
- cout << "NO";
- }
- cin.close();
- cout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement