#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int A[100000]; vector edge[100000]; int parent[100000]; int dp[100000][2][2]; //dp[i][j]... node i as a parent, j=1 must use i's parent void dfs(int p){ // //cout < m; //cout << p <<", "<< o <<", "<< f<A[p] &&o==0){ m[A[n]]=max(m[A[n]],calc(n,1-o,1)); } if( A[n]::iterator it=m.begin(); int cnt=0; int cnt_wo_parent=0; dp[p][o][0]=0; dp[p][o][1]=0; while(it!= m.end()){ cnt++; dp[p][o][0]+=it->second; if( it->first!= A[parent[p]] ){ cnt_wo_parent++; dp[p][o][1]+=it->second; } it++; } dp[p][o][0]+=cnt*(cnt-1)/2; dp[p][o][1]+=cnt_wo_parent*(cnt_wo_parent-1)/2; if( o==0 && A[parent[p]]>A[p]) dp[p][o][1]+=cnt_wo_parent; if( o==1 && A[parent[p]]> N; for( int i = 0 ; i > A[i]; } for( int i = 0; i < N-1 ; i++ ){ int x,y; cin >> x >> y; x--;y--; edge[x].push_back(y); edge[y].push_back(x); } memset(parent,-1,sizeof(parent)); if( N <= 2 ){ cout<<0<