daily pastebin goal
4%
SHARE
TWEET

Parada

a guest Feb 21st, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <bitset>
  4. using namespace std;
  5. int n,a,b,wynik,wynik2;
  6. vector <int> v[200001];
  7. bitset <200001> t;
  8. int funkcja(int x)
  9. {
  10.     int n1=0;
  11.     int n2=0;
  12.     int m;
  13.     t[x]=1;
  14.     for(int i=0;v[x].size()>i;i++)
  15.     {
  16.         if(t[v[x][i]]==0)
  17.         {
  18.             m=funkcja(v[x][i]);
  19.             if(m>n2)
  20.                 swap(m,n2);
  21.             if(n2>n1)
  22.                 swap(n1,n2);
  23.         }
  24.     }
  25.     wynik2=n1+n2+v[x].size()-2+(n2==0);
  26.     wynik=max(wynik2,wynik);
  27.     return n1+v[x].size()-2+(n1==0);
  28. }
  29. int main()
  30. {
  31.   cin>>n;
  32.   for(int i=1;n>i;i++)
  33.   {
  34.       cin>>a>>b;
  35.       v[a].push_back(b);
  36.       v[b].push_back(a);
  37.   }
  38.   funkcja(1);
  39.   cout<<wynik;
  40.     return 0;
  41. }
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