- #include<iostream>
- using namespace std;
- int main()
- {
- int N;
- cin>>N;
- int *ar = new int[N];
- for(int i=0;i<N;i++)
- cin>>ar[i];
- int **a = new int* [N];
- for(int i=0;i<N;i++){
- a[i]=new int [N];
- for(int j=0;j<N;j++){
- a[i][j]=-1;
- }
- }
- int u,v;
- for(int i=0;i<N-1;i++){
- cin>>u>>v;
- a[u][v]=ar[v];
- }
- int k;int count=0;
- int j,flg;
- for(int i=0;i<N;i++){
- k=ar[i];flg=1;
- for(j=0;j<N-1 && flg;j++)
- {
- if(!(a[i][j] == -1 || a[i][j] == k))
- flg=0;
- }
- if(flg)
- count++;
- }
- cout<<count<<endl;
- for(int i=0;i<N;i++)
- delete[] a[i];
- delete[] ar;
- return 0;
- }
Untitled
Posted by Anonymous on Wed 9th Sep 2015 13:38
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.