CT45091

Navigator's Garnet corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the trading post of Goldmeadow. Navigator spreads the corridors records across the table and picks up a sharp pencil. 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 <= 1906; the input is a connected tree.

Example 1:

Input: 1440 505 751 361 395 119 1345 1139 1249 706 916 458 480 176 610 373 977 274 794 5 142 439 493 113 374 36 381 69 80 29 1224 90 1180 8 215 1146 1151 122 241 274 527 1053 1308 628 1286 196 254 465 1252 289 362 103 283 378 534 853 1093 14 1088 554 651 13 506 482 709 168 823 157 303 420 1250 1022 1313 337 1197 939 1113 17 32 555 893 452 804 202 237 367 659 140 313 179 773 385 663 16 17 102 156 181 555 675 917 810 1171 114 117 292 665 679 1222 86 592 18 336 28 326 160 210 50 669 120 467 785 945 486 929 69 556 130 861 242 385 312 535 203 316 280 921 216 1404 234 1379 797 1175 39 224 709 1269 712 734 186 1111 241 430 252 1168 122 1289 50 1186 510 1367 6 212 618 962 654 1023 128 364 464 1024 380 602 173 518 293 1253 605 841 238 262 936 1418 376 760 577 1208 65 1012 301 329 336 789 244 1027 1 22 63 …
Output: 26

Example 2:

Input: 590 144 290 160 497 79 99 72 74 5 26 195 260 13 19 302 507 151 298 266 291 149 191 319 331 50 93 191 429 10 259 336 487 71 201 77 153 216 518 128 524 43 558 118 348 13 27 452 580 117 320 308 454 160 258 279 308 19 95 355 381 77 128 9 47 42 323 7 10 280 390 298 403 334 482 359 434 11 40 135 383 151 461 71 305 75 179 294 449 24 166 33 150 414 574 312 400 12 61 123 257 161 297 11 59 241 346 10 339 185 456 330 493 32 207 74 326 116 377 84 365 215 288 124 416 188 313 137 495 409 472 1 187 65 89 186 239 96 177 375 423 174 444 220 414 53 103 150 225 22 170 151 542 37 51 299 424 315 355 216 471 153 303 199 318 215 567 235 272 18 427 101 366 157 564 261 300 105 208 109 522 173 193 388 486 160 228 285 460 327 404 33 174 194 222 242 247 32 540 229 249 296 333 396 437 51 317 385 453 27 119 78 344 63 4…
Output: 26

Example 3:

Input: 1161 813 1109 186 197 187 454 234 978 353 848 556 998 953 983 28 376 866 1125 7 510 152 416 510 712 1062 1131 61 165 91 97 277 881 282 1032 475 831 119 567 329 1150 11 969 344 970 107 130 262 287 56 738 8 168 1014 1149 633 903 313 573 3 32 62 84 760 817 682 702 346 348 595 723 194 290 2 18 340 475 16 156 694 926 189 967 100 159 131 661 94 538 133 211 14 68 401 652 308 500 379 439 595 997 521 783 420 734 702 887 470 1102 462 1120 828 1133 150 1107 378 682 50 136 329 1095 22 28 741 945 200 334 553 883 945 1017 24 292 19 350 333 362 326 655 40 62 510 815 110 414 391 942 81 491 350 564 61 281 51 79 373 649 864 1015 104 536 30 193 650 657 5 1062 263 371 377 837 58 586 173 934 45 319 68 833 14 123 294 327 125 1007 621 740 532 989 314 1013 170 622 31 82 87 619 329 508 755 949 385 583 308 489 1072…
Output: 23

Constraints:

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

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