Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <bitset>
- using namespace std;
- int n,a,b,wynik,wynik2;
- vector <int> v[200001];
- bitset <200001> t;
- int funkcja(int x)
- {
- int n1=0;
- int n2=0;
- int m;
- t[x]=1;
- for(int i=0;v[x].size()>i;i++)
- {
- if(t[v[x][i]]==0)
- {
- m=funkcja(v[x][i]);
- if(m>n2)
- swap(m,n2);
- if(n2>n1)
- swap(n1,n2);
- }
- }
- wynik2=n1+n2+v[x].size()-2+(n2==0);
- wynik=max(wynik2,wynik);
- return n1+v[x].size()-2+(n1==0);
- }
- int main()
- {
- cin>>n;
- for(int i=1;n>i;i++)
- {
- cin>>a>>b;
- v[a].push_back(b);
- v[b].push_back(a);
- }
- funkcja(1);
- cout<<wynik;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement