SHARE
TWEET

#639

bluetastymelon Feb 18th, 2020 79 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("inaltime.in");
  7. ofstream g("inaltime.out");
  8.  
  9. int a[101][101],q[101],t[101],viz[101],poz,n,mx;
  10.  
  11. void BFS(int start)
  12. {
  13.     int p,u;
  14.     p=u=1;
  15.     q[1]=start;
  16.     viz[start]=1;
  17.     while(p<=u)
  18.     {
  19.         int x=q[p++];
  20.         for(int i=1;i<=n;i++)
  21.             if(a[x][i] and viz[i]==0)
  22.             {
  23.                 q[++u]=i;
  24.                 viz[i]=viz[x]+1;
  25.                 if(viz[i]>mx)
  26.                     mx=viz[i];
  27.             }
  28.     }
  29. }
  30.  
  31. void citire()
  32. {
  33.     int i;
  34.     f>>n;
  35.     for(i=1;i<=n;i++)
  36.     {
  37.         f>>t[i];
  38.         if(t[i]==0)
  39.             poz=i;
  40.         a[i][t[i]]=a[t[i]][i]=1;
  41.     }
  42. }
  43.  
  44. int main()
  45. {
  46.     int i,x;
  47.     citire();
  48.     BFS(poz);
  49.     g<<mx;
  50.     return 0;
  51. }
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