Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define N 111111
- using namespace std;
- int es[N],next[N],c,n,first[N],f[N];
- void add(int x,int y){
- next[++c]=first[x];first[x]=c;
- es[c]=y;
- }
- void dfs(int v,int p){
- for (int h=first[v];h;h=next[h]) if (es[h]!=p){
- dfs(es[h],v);
- f[v]=max(f[v],f[es[h]]);
- }
- ++f[v];
- }
- int main(){
- cin>>n;
- for (int i=0;i<n-1;++i){
- int x,y;
- cin>>x>>y;
- add(x,y);
- add(y,x);
- }
- dfs(1,-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment