Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- int tree[200001][3];
- int hgt = -1;
- void height(int curr, int h){
- hgt = (h > hgt) ? h : hgt;
- if (tree[curr][1] != 0){
- height(tree[curr][1], h+1);
- }
- if (tree[curr][2] != 0){
- height(tree[curr][2], h+1);
- }
- }
- int main() {
- ifstream fin("height.in");
- ofstream fout("height.out");
- int n, i, temp;
- fin >> n;
- if (n == 0){
- fout << 0;
- return 0;
- }
- for (i = 1; i <= n; i++) {
- fin >> tree[i][0];
- fin >> tree[i][1];
- fin >> tree[i][2];
- }
- height(1, 1);
- fout << hgt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement