SHARE
TWEET

#650

bluetastymelon Feb 18th, 2020 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("knivel.in");
  7. ofstream g("knivel.out");
  8.  
  9. int a[101][101],t[101],viz[101],poz,n,cont=1,k;
  10.  
  11. void DFS(int start)
  12. {
  13.     viz[start]=cont;
  14.     for(int i=1;i<=n;i++)
  15.         if(a[start][i] and viz[i]==0)
  16.         {
  17.             cont++;
  18.             DFS(i);
  19.             cont--;
  20.         }
  21. }
  22.  
  23. void citire()
  24. {
  25.     int i;
  26.     f>>n>>k;
  27.     for(i=1;i<=n;i++)
  28.     {
  29.         f>>t[i];
  30.         if(t[i]==0)
  31.             poz=i;
  32.         a[i][t[i]]=a[t[i]][i]=1;
  33.     }
  34. }
  35.  
  36. int main()
  37. {
  38.     int i;
  39.     citire();
  40.     DFS(poz);
  41.     for(i=1;i<=n;i++)
  42.         if(viz[i]==k)
  43.             g<<i<<" ";
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top