pastebin - collaborative debugging tool
kpaste.net RSS


Untitled
Posted by Anonymous on Wed 9th Sep 2015 13:38
raw | new post

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.         int N;
  6.         cin>>N;
  7.         int *ar = new int[N];
  8.         for(int i=0;i<N;i++)
  9.                 cin>>ar[i];
  10.         int **a = new int* [N];
  11.         for(int i=0;i<N;i++){
  12.                 a[i]=new int [N];
  13.                 for(int j=0;j<N;j++){
  14.                         a[i][j]=-1;
  15.         }
  16.         }
  17.         int u,v;
  18.         for(int i=0;i<N-1;i++){
  19.                 cin>>u>>v;
  20.                 a[u][v]=ar[v];
  21.         }
  22.         int k;int count=0;
  23.         int j,flg;
  24.         for(int i=0;i<N;i++){
  25.             k=ar[i];flg=1;
  26.                 for(j=0;j<N-1 && flg;j++)
  27.                 {
  28.                     if(!(a[i][j] == -1 || a[i][j] == k))
  29.                         flg=0;
  30.        
  31.                 }
  32.                 if(flg)
  33.                         count++;
  34.         }
  35.         cout<<count<<endl;
  36.         for(int i=0;i<N;i++)
  37.                 delete[] a[i];
  38.         delete[] ar;
  39.         return 0;
  40. }

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at