fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. void *wmem;
  5. char memarr[96000000];
  6. template<class S, class T> inline S max_L(S a,T b){
  7. return a>=b?a:b;
  8. }
  9. template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  10. static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  11. (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  12. (*arr)=(T*)(*mem);
  13. (*mem)=((*arr)+x);
  14. }
  15. struct graph{
  16. int N;
  17. int *es;
  18. int **edge;
  19. void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
  20. int i;
  21. N = N__;
  22. walloc1d(&es, N, mem);
  23. walloc1d(&edge, N, mem);
  24. for(i=(0);i<(N);i++){
  25. es[i] = 0;
  26. }
  27. for(i=(0);i<(M);i++){
  28. es[A[i]]++;
  29. es[B[i]]++;
  30. }
  31. for(i=(0);i<(N);i++){
  32. walloc1d(&edge[i], es[i], mem);
  33. }
  34. for(i=(0);i<(N);i++){
  35. es[i] = 0;
  36. }
  37. for(i=(0);i<(M);i++){
  38. edge[A[i]][es[A[i]]++] = B[i];
  39. edge[B[i]][es[B[i]]++] = A[i];
  40. }
  41. }
  42. void getDist(int root, int res[], void *mem = wmem){
  43. int i;
  44. int j;
  45. int k;
  46. int*q;
  47. int s;
  48. int z;
  49. walloc1d(&q, N, &mem);
  50. for(i=(0);i<(N);i++){
  51. res[i]=-1;
  52. }
  53. res[root]=0;
  54. s=0;
  55. z=1;
  56. q[0]=root;
  57. while(z){
  58. i=q[s++];
  59. z--;
  60. for(j=(0);j<(es[i]);j++){
  61. k=edge[i][j];
  62. if(res[k]>=0){
  63. continue;
  64. }
  65. res[k]=res[i]+1;
  66. q[s+z++]=k;
  67. }
  68. }
  69. }
  70. }
  71. ;
  72. #define main dummy_main
  73. int main(){
  74. wmem = memarr;
  75. return 0;
  76. }
  77. #undef main
  78. int N;
  79. int M;
  80. int A[20000];
  81. int B[20000];
  82. int dist[20000];
  83. class Solution{
  84. public:
  85. int treeDiameter(vector<vector<int>>& edges){
  86. int i;
  87. dummy_main();
  88. graph g;
  89. N = edges.size() + 1;
  90. M = edges.size();
  91. for(i=(0);i<(M);i++){
  92. A[i] = edges[i][0];
  93. B[i] = edges[i][1];
  94. }
  95. g.setEdge(N, M, A, B);
  96. g.getDist(0, dist);
  97. {
  98. int KL2GvlyY;
  99. int Q5VJL1cS = 0;
  100. int e98WHCEY;
  101. int cTE1_r3A;
  102. int RZTsC2BF;
  103. for(KL2GvlyY=(0);KL2GvlyY<(((N)-1)+1);KL2GvlyY++){
  104. cTE1_r3A = dist[KL2GvlyY];
  105. if(Q5VJL1cS==0 || e98WHCEY<cTE1_r3A){
  106. e98WHCEY = cTE1_r3A;
  107. Q5VJL1cS = 1;
  108. RZTsC2BF = KL2GvlyY;
  109. }
  110. }
  111. g.getDist(RZTsC2BF, dist);
  112. }
  113. {
  114. int FmcKpFmN;
  115. int xr20shxY;
  116. if(N==0){
  117. xr20shxY = 0;
  118. }
  119. else{
  120. xr20shxY = dist[0];
  121. for(FmcKpFmN=(1);FmcKpFmN<(N);FmcKpFmN++){
  122. xr20shxY = max_L(xr20shxY, dist[FmcKpFmN]);
  123. }
  124. }
  125. return xr20shxY;
  126. }
  127. }
  128. }
  129. ;
  130. // cLay varsion 20191102-1
  131.  
  132. // --- original code ---
  133. // #define main dummy_main
  134. // {}
  135. // #undef main
  136. //
  137. // int N, M, A[2d4], B[2d4];
  138. // int dist[2d4];
  139. //
  140. // class Solution {
  141. // public:
  142. // int treeDiameter(vector<vector<int>>& edges) {
  143. // dummy_main();
  144. // graph g;
  145. // N = edges.size() + 1;
  146. // M = edges.size();
  147. // rep(i,M) A[i] = edges[i][0], B[i] = edges[i][1];
  148. // g.setEdge(N, M, A, B);
  149. // g.getDist(0, dist);
  150. // g.getDist(argmax(dist(N)), dist);
  151. // return max(dist(N));
  152. // }
  153. // };
  154.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty