CT37144

The Wild Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The inventory keeper Zane has been asked to forecast next month's demand. On the desk lies a long table of canals 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 <= 2623; the input is a connected tree.

Example 1:

Input: 737 84 236 108 181 649 673 100 145 279 536 15 87 27 164 279 644 607 725 127 550 613 618 370 414 74 77 11 25 115 549 79 511 392 459 42 65 325 471 311 502 13 32 23 347 5 67 141 328 569 610 102 138 170 265 102 222 238 253 214 589 232 601 147 193 136 357 245 737 52 648 51 72 33 122 9 18 444 566 101 119 126 464 204 393 560 733 427 439 106 120 228 245 249 435 73 249 26 49 406 481 335 415 504 574 30 31 328 636 67 118 112 155 346 364 186 665 70 555 129 143 218 353 168 242 632 692 178 335 152 199 90 148 319 378 38 674 305 334 466 635 311 591 44 309 297 398 5 14 346 366 131 149 13 182 168 299 116 329 521 696 354 617 214 530 196 391 360 444 75 203 135 139 552 698 228 250 136 186 23 64 32 134 515 731 3 30 484 702 8 320 23 500 74 217 260 515 94 111 139 431 330 729 67 345 455 492 357 456 200 208 65 174 …
Output: 20

Example 2:

Input: 1696 357 614 206 1244 680 778 911 977 1067 1222 31 42 227 1622 519 612 323 663 139 240 844 1396 479 1556 200 342 734 1506 83 166 70 79 578 1643 679 848 167 844 1135 1460 1381 1641 226 770 293 792 543 654 540 1262 1377 1654 1174 1306 491 1672 53 1348 794 1181 720 973 137 388 416 727 210 972 324 489 134 331 211 698 624 720 557 1289 395 1638 11 262 89 389 135 1056 444 570 720 940 717 1681 719 1342 541 1518 208 1070 280 310 1075 1325 50 1223 257 1280 66 742 43 1449 173 569 34 44 1219 1624 87 505 168 335 8 140 505 814 202 553 362 830 281 656 4 111 1342 1392 771 1027 119 383 105 777 25 860 1196 1632 540 1147 837 1686 229 435 949 1540 808 1271 21 208 592 1329 376 541 522 697 95 252 166 548 71 233 323 366 493 587 1238 1255 237 794 1208 1663 259 780 55 56 181 662 143 428 638 1134 1422 1649 30 1008 …
Output: 26

Example 3:

Input: 2371 419 478 316 624 1120 1313 970 1267 717 783 15 57 549 625 249 780 172 1581 991 1941 267 1690 718 1556 1518 1868 45 296 103 1354 37 60 1330 2105 149 1526 387 2165 295 426 116 1346 1507 2004 176 642 389 675 1299 2022 15 20 654 1103 990 1489 967 1681 100 379 1330 1777 1288 1931 948 1684 326 1462 92 925 175 705 1041 1278 1228 2190 121 1217 1121 1525 242 850 6 177 459 535 430 652 749 894 516 1039 144 471 900 1735 1069 1234 572 1799 317 844 170 1922 942 1221 225 446 614 2201 422 555 558 629 775 1096 295 1570 222 1562 732 1611 281 476 774 2300 21 130 602 721 661 735 191 701 36 167 1194 1631 241 287 824 1659 289 591 1976 2037 557 809 404 2281 60 448 1110 1949 364 1665 259 2328 3 1415 236 1454 252 325 363 1352 1965 2099 183 647 2206 2269 273 1014 475 2331 277 1738 287 1168 1154 1734 32 34 88 16…
Output: 34

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.