#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class MaxMinTreeGame { public:
	int findend(vector <int> edges, vector <int> costs)
	{
		int N = costs.size();
		vector<int> deg(N);
		for(int i=0; i<N-1; ++i) {
			deg[i+1]++;
			deg[edges[i]]++;
		}
		int maxLeaf = 0;
		for(int i=0; i<N; ++i)
			if(deg[i]==1)
				maxLeaf = max(maxLeaf, costs[i]);
		return maxLeaf;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, MaxMinTreeGame().findend(edges, costs));}
int main(){

CASE(0)
	int edges_[] = {0};
	  vector <int> edges(edges_, edges_+sizeof(edges_)/sizeof(*edges_)); 
	int costs_[] = {4,6};
	  vector <int> costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); 
	int _ = 6; 
END
CASE(1)
	int edges_[] = {0,1};
	  vector <int> edges(edges_, edges_+sizeof(edges_)/sizeof(*edges_)); 
	int costs_[] = {4,6,5};
	  vector <int> costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); 
	int _ = 5; 
END
CASE(2)
	int edges_[] = {0,1,2,3};
	  vector <int> edges(edges_, edges_+sizeof(edges_)/sizeof(*edges_)); 
	int costs_[] = {0,1,0,1,0};
	  vector <int> costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); 
	int _ = 0; 
END
CASE(3)
	int edges_[] = {0,0,0};
	  vector <int> edges(edges_, edges_+sizeof(edges_)/sizeof(*edges_)); 
	int costs_[] = {5,1,2,3};
	  vector <int> costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); 
	int _ = 3; 
END
CASE(4)
	int edges_[] = {0,0};
	  vector <int> edges(edges_, edges_+sizeof(edges_)/sizeof(*edges_)); 
	int costs_[] = {3,2,5};
	  vector <int> costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); 
	int _ = 5; 
END
/*
CASE(6)
	int edges_[] = ;
	  vector <int> edges(edges_, edges_+sizeof(edges_)/sizeof(*edges_)); 
	int costs_[] = ;
	  vector <int> costs(costs_, costs_+sizeof(costs_)/sizeof(*costs_)); 
	int _ = ; 
END
*/
}
// END CUT HERE
