Advertisement
tumaryui

Untitled

Sep 6th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. pii diam(int v, int pr = -1, int dist = 0) {
  2. int bg = v;
  3. for(auto it: gr[v]) {
  4. if(it != pr) {
  5. pii tmp = diam(it, v);
  6. if(tmp.fr > dist) {
  7. bg = tmp.sc;
  8. dist = tmp.fr;
  9. }
  10. }
  11. }
  12. return {dist + 1, bg};
  13. }
  14.  
  15. main() {
  16. int u = diam(1).second
  17. int diamdist = diam(u).first // получаем дистанцию
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement