Skip to content

Instantly share code, notes, and snippets.

@koosaga
Created June 29, 2017 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koosaga/f873af82061fb59fa34961b03b47bbbd to your computer and use it in GitHub Desktop.
Save koosaga/f873af82061fb59fa34961b03b47bbbd to your computer and use it in GitHub Desktop.
int dfs(int x, int p){
vector<int> e;
for(auto &i : tr[x]){
if(i == p) continue;
e.push_back(dfs(i, x));
}
if(e.empty()) return 1;
sort(e.begin(), e.end());
for(int i=0; i<e.size()-1; i++){
v.push_back(e[i]);
}
return e.back() + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment