Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int main() {
- ifstream fin("height.in");
- ofstream fout("height.out");
- int N;
- int Left_element;
- int Right_element;
- int key;
- int max;
- int i;
- fin >> N;
- if (N < 1) {fout << N;} else {
- int *array = new int[N+1];
- array[1] = 1;
- for (i = 1; i <= N; i++) {
- fin >> key >> Left_element >> R;
- if (Left_element > 0) {array[Left_element] = array[i]+1;};
- if (Right_element > 0) {array[Right_element] = array[i]+1;};
- };
- max = array[N];
- for (int i = 1; i < N; i++) {
- if (max < array[i]) {max=array[i];};
- };
- fout << max;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment