CT39419

The Longest Trail at Bloomglass

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the orchid house of Bloomglass, someone must price the new merchandise line. This year the task falls to June, armed only with the tunnels register. Task: A tree has n nodes and n-1 unweighted edges. Print its diameter (in edges). Input format: First line: n. Next n-1 lines: u v. Output format: Print the diameter. Constraints: 1 <= n <= 3488; the input is a connected tree.

Example 1:

Input: 2387 702 719 419 514 84 109 952 1600 1722 2336 1348 2366 410 1825 359 1566 624 1321 874 2097 40 2228 967 1254 1004 1850 2267 2294 480 1182 846 1471 8 23 871 1460 148 223 1221 1529 1653 1944 898 1018 356 668 396 930 2086 2155 390 845 136 172 965 1754 1576 2005 1152 1943 830 1115 281 447 195 397 948 1913 1184 1614 62 197 1487 1908 363 743 137 181 1783 2114 407 671 147 345 112 2021 274 435 1214 1589 596 637 332 2306 1296 1319 78 235 518 1006 327 412 330 585 1327 1897 185 562 1730 1937 1234 1313 462 695 1290 1651 144 768 520 1519 1580 1635 130 415 100 112 46 1303 1041 1538 326 464 964 2206 1919 2060 807 1712 231 1625 151 1145 1234 1928 51 700 839 1181 1809 1969 1130 1924 303 744 2 84 580 969 1130 1670 5 143 1468 2014 9 166 6 490 1280 2000 260 1125 1445 2174 1612 1758 186 486 2064 2193 390 1180…
Output: 28

Example 2:

Input: 1106 10 231 40 337 187 476 950 996 659 829 386 709 16 31 227 244 490 506 12 486 122 357 35 289 84 183 115 205 240 1104 289 697 8 33 522 685 86 913 355 997 396 613 761 820 318 592 163 333 142 470 748 943 90 666 208 423 20 821 158 1064 401 1063 407 889 246 1083 38 760 427 1000 291 474 63 82 179 373 31 382 168 253 348 1007 29 859 379 629 617 671 572 1014 126 386 57 91 373 567 270 546 1 12 43 73 239 886 137 557 164 195 20 232 973 1034 799 931 20 97 736 932 204 880 488 1024 163 317 32 758 23 63 393 478 56 216 90 368 21 94 8 119 222 799 259 355 157 499 734 832 144 242 512 908 341 999 171 239 437 494 168 447 496 1073 490 659 93 169 309 518 724 947 188 408 62 194 562 861 491 545 591 684 32 207 1 279 607 812 249 698 747 1068 106 168 2 138 557 871 323 1006 602 884 404 739 663 775 34 37 412 823 22 48…
Output: 22

Example 3:

Input: 260 51 54 43 44 35 120 84 243 11 37 70 227 41 106 156 251 60 211 117 140 68 244 16 221 138 173 194 238 25 28 5 79 63 174 34 89 15 22 31 60 7 17 11 155 6 16 9 13 14 259 150 201 150 235 28 73 39 111 203 219 37 223 89 133 2 11 29 121 89 195 9 23 46 112 55 184 7 218 36 129 7 94 65 68 18 74 8 156 160 252 9 137 20 24 21 116 7 15 166 233 40 103 64 162 150 180 42 154 25 213 74 141 123 242 83 161 33 46 68 222 117 241 169 181 195 229 34 48 11 128 27 87 9 26 27 212 75 147 62 90 5 8 52 86 252 257 9 255 63 250 145 210 37 45 5 107 12 64 106 206 40 52 27 253 31 230 4 30 76 144 61 67 220 224 13 138 74 159 12 72 35 69 44 65 45 99 74 153 6 33 155 160 30 165 59 136 83 193 5 47 2 81 43 191 88 124 53 168 7 200 31 82 206 246 226 236 163 247 85 151 83 177 16 101 10 66 85 102 168 245 9 88 202 215 97 127 28 83 99 …
Output: 17

Constraints:

1 <= n <= 3488; the input is a connected tree.

Loading...
Test Cases:No test cases
No test cases available.
The Longest Trail at Bloomglass - MEDIUM Coding Problem | CodeTikki