CT47541

The Longest Trail of the Mossy corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The reckoner Gail has been asked to reorganize the archive shelves. On the desk lies a long table of corridors readings. 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 <= 3160; the input is a connected tree.

Example 1:

Input: 1914 869 1501 786 1604 992 1452 371 750 84 254 175 1046 987 1449 53 536 854 944 213 428 123 194 60 124 1142 1890 547 866 6 1411 1095 1440 545 578 184 386 1031 1283 112 170 295 593 403 1061 1502 1907 325 676 62 474 613 1648 1530 1622 4 221 326 885 47 87 72 230 158 373 35 217 1254 1313 178 874 646 1109 164 452 562 1589 195 250 429 563 485 610 935 1372 22 165 940 1161 169 804 474 780 251 798 462 1179 74 181 285 356 411 1777 116 175 505 735 745 792 548 1100 249 357 172 640 282 1123 151 351 530 546 439 1060 756 1564 1080 1850 312 1400 813 876 38 1390 628 658 319 1549 386 403 62 167 998 1674 366 484 325 1796 17 36 1244 1780 274 279 273 1025 1120 1651 48 321 101 1172 320 339 277 382 730 788 482 574 425 1486 101 605 262 436 108 218 746 1398 524 1719 3 642 696 963 385 1141 301 732 855 910 476 976 4…
Output: 25

Example 2:

Input: 2017 914 1551 66 1745 456 1216 353 1780 769 1736 47 1487 214 488 686 1738 955 1389 575 632 146 1658 544 1700 67 148 669 956 331 1796 390 1694 321 1077 512 744 599 862 934 1792 1270 1869 141 213 152 327 83 531 400 486 739 1401 24 814 20 105 230 1350 494 536 724 1831 522 631 173 839 38 44 5 21 2 79 1187 1679 1419 1709 106 1985 344 528 323 361 844 1391 61 197 68 442 1078 1909 673 721 320 1614 12 80 92 497 309 1090 1409 1455 674 849 165 886 35 250 427 635 840 1447 7 25 274 581 689 1100 881 995 122 728 460 1449 232 1508 627 1332 221 256 101 1477 953 1275 451 1376 984 1056 650 673 767 1200 117 121 28 74 221 914 929 997 320 736 88 124 492 753 800 1494 84 156 175 260 630 763 637 693 659 1534 111 1245 4 100 147 477 138 1744 183 440 127 1850 357 936 382 1798 458 730 213 835 9 1014 5 17 1 4 642 864 1…
Output: 29

Example 3:

Input: 456 116 158 173 209 346 413 163 254 416 425 210 334 200 201 271 353 15 51 33 138 56 84 12 196 97 181 68 82 268 271 29 50 264 340 43 85 216 240 286 385 94 255 332 338 86 344 340 411 129 142 117 119 336 355 37 235 29 37 226 261 302 315 67 319 155 229 70 444 16 135 123 127 9 318 36 211 54 252 52 398 31 128 65 257 29 234 7 12 11 123 71 102 155 213 42 329 163 197 138 184 128 239 251 341 124 364 10 53 60 223 311 369 15 25 37 156 23 24 40 47 31 141 274 303 53 57 40 259 31 193 16 94 36 105 266 455 24 33 106 176 8 108 326 330 146 187 24 28 17 52 195 203 110 155 187 277 228 339 211 323 14 101 231 404 79 198 144 241 7 83 57 230 149 406 285 335 71 129 28 378 64 66 203 279 109 414 53 227 84 104 44 100 118 268 39 397 30 113 24 371 36 61 120 269 1 22 57 393 3 5 16 407 2 15 352 451 240 438 17 59 143 192 1…
Output: 27

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Longest Trail of the Mossy corridors - MEDIUM Coding Problem | CodeTikki