CT53771

Tracker and the Garnet routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Tracker found an old ledger of routes in the cellar attic at the honey farms of Buzzwell. The margin notes pose a precise question. 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 <= 3563; the input is a connected tree.

Example 1:

Input: 3056 1017 1571 560 2810 415 984 382 1991 87 116 1007 1927 1303 1305 2560 2822 1877 2669 68 161 1391 1985 583 2310 954 2203 443 609 675 2105 1036 2668 343 521 127 321 129 156 307 1209 360 2358 1174 1266 1481 1697 212 695 91 1395 1070 1309 2268 2470 211 363 15 135 1784 2712 1650 2238 879 1060 1915 2042 450 763 805 1046 442 584 309 1281 191 446 732 846 504 636 856 1651 813 2282 1410 2296 752 1380 283 562 366 3056 1356 2683 158 392 22 1182 109 526 2159 2871 316 538 1116 2362 265 1049 560 2179 635 742 107 208 86 2365 2181 2608 369 508 141 164 1668 3029 2344 2728 1678 1820 34 421 253 711 1359 1489 1884 2143 1522 1994 920 1077 412 426 852 1771 388 2794 333 2535 1320 1814 726 1541 180 543 1882 2256 584 1317 689 852 476 1085 18 110 188 432 339 725 441 2821 114 1164 43 56 1393 2734 421 1375 730 2528…
Output: 30

Example 2:

Input: 1097 490 915 963 978 4 24 778 1095 894 1050 384 722 129 930 201 662 141 447 184 269 59 234 18 506 524 766 335 474 161 885 358 584 723 852 20 316 112 1056 278 687 67 178 393 807 356 994 292 505 115 384 82 95 393 398 292 705 358 463 312 379 158 258 34 228 51 983 58 93 848 924 442 998 432 732 409 708 420 643 11 547 73 396 9 628 429 627 3 820 570 926 203 1065 936 984 718 949 270 1000 595 1086 7 65 279 376 751 767 487 904 486 504 394 432 46 289 378 462 566 910 18 257 347 713 449 768 83 270 406 892 465 673 246 253 356 858 1 7 213 624 893 1081 213 562 808 1028 512 1004 4 5 701 996 434 538 713 1082 378 875 28 58 99 611 414 869 225 346 416 464 297 1044 155 967 176 500 5 38 167 786 295 558 116 719 73 321 184 335 207 543 340 764 33 135 494 700 129 142 465 658 51 292 151 716 21 795 62 186 14 25 311 10…
Output: 26

Example 3:

Input: 1749 185 420 77 83 956 1593 589 895 599 703 515 1424 445 725 574 984 878 1499 1060 1141 6 33 141 464 207 720 62 706 683 1419 1240 1351 239 916 132 804 47 780 806 1425 319 1171 859 1034 862 1304 195 273 73 1735 490 1530 148 565 1216 1609 398 700 178 996 6 128 593 635 278 460 183 1391 724 1269 563 564 34 1371 114 206 1390 1737 1071 1111 92 230 67 294 171 252 844 921 263 1414 288 1375 384 517 785 1330 57 496 943 1679 8 208 269 303 430 977 145 162 621 1612 176 397 82 243 288 350 304 662 755 1318 140 241 571 1389 18 29 668 1550 39 256 703 1138 292 973 771 1249 41 1003 439 743 36 187 221 504 73 839 398 541 57 87 215 475 282 1011 758 812 144 150 762 1077 218 931 587 1313 364 1551 91 1095 133 678 426 852 779 1691 91 98 7 19 322 400 493 701 1021 1392 153 1555 427 663 422 1315 858 1188 53 761 346 51…
Output: 28

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tracker and the Garnet routes - MEDIUM Coding Problem | CodeTikki