CT57098

Bishop and the Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the foggy moor of Greyfen; Bishop weighs the day's bridges manifests and starts the calculations. 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 <= 3972; the input is a connected tree.

Example 1:

Input: 480 147 227 174 183 36 51 209 395 92 119 61 149 31 299 108 254 242 256 169 453 7 230 75 87 3 9 127 225 135 265 420 458 11 276 44 82 264 297 86 381 85 176 9 42 140 335 50 322 7 36 449 457 260 283 280 284 1 32 102 316 49 68 60 170 97 338 25 464 187 192 247 280 45 281 103 251 13 308 164 178 197 198 23 88 276 406 231 235 347 479 100 351 304 444 187 369 42 231 152 239 116 330 8 470 156 202 123 465 49 104 96 164 94 477 19 289 149 379 220 282 51 258 97 117 162 336 192 214 73 80 23 109 18 21 125 141 43 124 250 450 60 241 46 59 225 266 114 242 26 431 373 398 160 430 210 244 59 429 44 70 20 112 13 340 2 25 24 67 4 10 58 92 30 303 271 416 19 236 42 99 13 15 190 219 88 136 20 451 127 468 190 399 245 253 127 233 24 60 290 305 146 223 19 421 17 19 1 6 156 342 5 23 195 307 20 31 35 65 264 273 1 2 343 374…
Output: 19

Example 2:

Input: 1151 654 926 679 1021 43 887 38 178 481 511 320 981 22 77 229 272 738 1056 591 851 118 1004 451 675 707 1025 464 572 449 551 258 1052 462 1018 733 1080 137 286 358 872 881 968 2 859 476 795 239 524 8 649 1 220 214 349 235 718 671 709 16 240 149 212 560 958 232 239 71 148 429 1044 96 195 107 108 336 969 100 757 768 898 64 177 332 445 140 184 131 143 318 728 209 561 549 762 47 742 836 1121 38 80 135 378 424 805 540 889 294 1084 772 780 586 620 291 313 191 704 949 1029 15 17 267 947 6 264 276 635 380 509 730 1040 147 228 373 827 630 899 415 440 518 930 447 744 63 202 352 690 203 320 193 990 149 166 694 865 32 916 276 352 131 364 48 82 601 662 15 42 437 737 35 74 127 1103 526 702 385 600 235 526 321 488 597 884 517 1086 129 329 467 535 68 293 58 72 12 438 820 1092 226 229 74 348 32 115 257 275…
Output: 25

Example 3:

Input: 2905 1355 2683 452 1956 37 550 647 1536 1474 2131 825 1572 584 590 498 1923 1416 2831 1837 2148 2490 2901 780 2399 612 2180 89 786 1521 2903 506 896 2762 2857 1564 2300 221 594 1624 2240 1295 2166 101 1054 240 545 184 710 45 87 41 410 22 1591 950 1491 836 1927 380 815 18 36 71 1686 560 1457 1258 1673 5 44 1194 1773 1787 2266 93 657 626 1915 344 2334 139 514 1058 1959 8 98 659 2199 358 577 2165 2490 912 2667 83 296 892 1266 688 775 496 1375 527 604 1046 1777 2318 2505 91 1553 216 1666 1380 1476 967 1194 235 2844 212 712 389 2530 569 890 117 256 409 771 140 325 263 2593 30 171 189 722 801 975 1259 1918 2225 2247 152 226 1084 1245 1109 1638 1282 1505 2274 2542 609 1997 2398 2494 1567 2559 2372 2811 2242 2435 227 520 161 2836 209 2118 85 235 979 1066 38 75 327 1212 1058 2333 95 1304 313 2454 1…
Output: 28

Constraints:

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

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