Created
June 29, 2017 15:36
-
-
Save koosaga/f873af82061fb59fa34961b03b47bbbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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