CT56873

The Rootwater Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the mangrove channels of Rootwater, Mira studies rows of canals entries. One clean number will settle the guild's oldest argument. 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 <= 1800; the input is a connected tree.

Example 1:

Input: 1569 301 1077 272 1418 292 729 29 96 44 138 29 1192 100 202 752 907 811 1309 386 629 431 1261 390 712 171 396 595 1114 326 1499 904 1098 22 394 187 260 13 60 543 1245 162 1039 28 104 106 177 179 759 2 5 24 49 191 579 144 898 104 223 6 23 442 619 258 620 42 78 293 306 478 1164 248 777 139 222 103 678 1106 1371 793 889 780 884 496 1445 622 1352 97 198 320 505 287 805 1344 1545 207 496 13 90 1095 1284 78 1047 539 803 1260 1419 991 1278 136 695 382 922 1342 1551 751 1219 1109 1154 72 371 861 1525 476 1320 840 861 124 266 269 277 430 1107 332 690 10 444 36 1485 547 958 362 1506 543 951 97 370 590 1540 584 821 193 650 772 1522 1079 1425 1286 1361 622 976 146 575 97 135 995 1493 303 1062 823 1052 327 617 94 544 908 1214 449 780 878 1292 738 1435 347 621 607 718 231 573 93 1462 509 995 242 264 201…
Output: 27

Example 2:

Input: 1259 52 1178 501 549 41 76 146 759 152 830 361 695 113 539 544 889 20 565 548 1020 57 605 253 423 217 1142 331 1001 53 445 108 284 227 683 774 891 162 249 655 981 614 633 477 657 484 654 169 733 390 977 247 280 55 952 94 167 341 431 33 87 499 569 817 1080 382 966 535 1092 267 994 305 859 975 1058 151 160 30 124 255 333 11 443 205 319 161 245 222 514 261 602 131 1010 56 1227 110 470 594 1138 13 123 122 535 392 974 328 1190 112 988 210 230 4 576 254 307 328 679 365 556 501 724 28 500 1051 1137 865 989 549 873 112 478 431 1177 780 990 991 1237 1041 1116 73 128 222 489 58 721 431 717 215 328 183 294 114 751 213 517 454 917 537 846 29 211 824 938 196 613 315 1077 574 1212 736 1185 143 705 452 563 52 67 949 951 150 324 430 582 395 1103 98 182 34 468 650 965 765 802 383 540 623 826 965 980 309 43…
Output: 26

Example 3:

Input: 613 70 79 192 225 80 519 429 552 26 461 328 401 379 583 193 296 160 340 146 282 10 419 117 327 201 211 90 166 115 323 477 566 254 604 311 475 79 103 399 423 111 363 7 14 84 597 42 90 137 591 137 281 508 518 126 399 246 550 19 56 1 12 357 495 228 511 27 204 166 407 4 325 271 395 236 275 26 574 365 515 229 356 221 258 506 524 24 34 125 295 355 562 251 272 258 435 4 302 208 257 174 332 131 177 12 100 84 326 56 68 116 291 139 171 27 130 401 608 198 219 57 242 151 328 28 303 29 217 207 415 53 84 234 384 22 31 179 455 254 482 133 488 115 571 533 557 139 265 381 385 136 215 107 181 6 207 57 110 16 197 11 23 7 13 387 530 74 175 194 279 34 216 31 603 67 404 189 470 11 83 4 379 233 355 29 449 264 318 146 220 18 25 15 237 89 154 10 24 12 30 57 58 35 259 385 492 30 139 56 101 222 474 47 155 332 358 46…
Output: 21

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rootwater Longest Trail - MEDIUM Coding Problem | CodeTikki