Advertisement
_no0B

Untitled

Jul 17th, 2021
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. //#include<cstdio>
  2. //#include<cassert>
  3. //#include<iostream>
  4. //#include<cstring>
  5. //#include<algorithm>
  6. #include<bits/stdc++.h>
  7. #include<ext/pb_ds/assoc_container.hpp>
  8. #include<ext/pb_ds/tree_policy.hpp>
  9. #define MAX ((int)2e9 + 5)
  10. #define MAXP ((int)1e5 + 5)
  11. #define MAXL ((ll)1e18 + 5)
  12. #define MAX_X ((int)2001)
  13. #define MAX_Y ((int)2001)
  14. #define pi acos(-1)
  15. //#define MOD ((int)1e9 + 7)
  16. #define MOD ((int)998244353 + 0)
  17. #define BAS ((int)1e6 + 3)
  18. //#define BAS ((int)2e5 + 3)
  19. #define N ((int)2e5 + 9)
  20. #define eps (1e-8)
  21. #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
  22. #define logn 17
  23. #define endl "\n"
  24. #define mpp make_pair
  25. #define BUCK 105
  26. #define LEF (idx<<1)
  27. #define RIG ((idx<<1)|1)
  28. //#define int ll
  29.  
  30.  
  31. using namespace std;
  32. using namespace __gnu_pbds;
  33.  
  34. typedef long long ll;
  35. typedef unsigned long long ull;
  36.  
  37. /*fast io
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(NULL);
  40. */
  41.  
  42.  
  43.  
  44.  
  45. typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
  46. typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_setp;
  47. /// o_set s;
  48. /// s.order_of_key(k) : Number of items strictly smaller than k .
  49. /// *(s.find_by_order(k)) : K-th element in a set (counting from zero).
  50.  
  51. typedef long double ldd;
  52.  
  53. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  54.  
  55. int my_rand(int l, int r)
  56. {
  57.     return uniform_int_distribution<int>(l,r) (rng);
  58. }
  59.  
  60. int dia[N] , dep[N];
  61.  
  62. void dfs(int n , int p)
  63. {
  64.     dep[n] = dia[n] = 0;
  65.     int mxx1 = 0 , mxx2 = 0;
  66.     for(int nxt:vec[n]){
  67.         if(nxt != p){
  68.             dfs(nxt , n);
  69.             dep[n] = max(dep[n] , dep[nxt] + 1);
  70.             dia[n] = max(dia[n] , dia[nxt]);
  71.             mxx2 = max(mxx2 , dep[nxt] + 1);
  72.             if(mxx2 > mxx1) swap(mxx1 , mxx2);
  73.         }
  74.     }
  75.     dia[n] = max(dia[n] , mxx1 + mxx2);
  76. }
  77.  
  78.  
  79. int main()
  80. {
  81.     /// problem: https://www.spoj.com/problems/RTREE/
  82.     dfs(root , 0);
  83.     while(q--){
  84.         /// code
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement