CT51793

The Sunspire Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the temple city of Sunspire; Baker weighs the day's tunnels 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 <= 1704; the input is a connected tree.

Example 1:

Input: 575 20 211 22 26 64 530 297 312 81 222 64 230 35 160 44 323 109 261 426 503 237 440 156 302 5 12 8 317 5 49 312 447 24 56 281 533 138 573 339 363 26 202 7 236 252 480 3 387 206 463 82 104 300 389 61 99 164 231 275 345 13 287 58 76 68 219 120 147 14 201 213 474 8 162 480 563 127 347 222 233 41 504 414 529 4 115 100 423 121 165 90 218 7 158 64 144 246 307 407 508 35 91 228 314 72 196 433 475 86 124 310 469 115 514 35 53 302 516 11 98 239 357 56 349 95 372 174 189 45 159 254 272 15 73 15 83 13 105 288 439 316 525 296 478 13 27 273 430 276 412 45 574 1 5 94 239 110 163 381 549 291 554 116 502 79 512 24 522 262 329 11 379 45 178 257 434 22 125 119 214 456 550 186 571 5 234 249 359 13 89 344 473 108 188 39 171 63 494 45 567 33 138 438 498 78 417 84 137 213 311 330 358 19 57 35 107 230 253 219 31…
Output: 21

Example 2:

Input: 1381 323 454 450 622 544 1029 321 503 243 1201 122 1023 1255 1380 485 1357 81 372 415 1101 318 998 316 1355 513 1276 1 4 377 1123 177 197 768 1227 177 365 110 1218 4 36 205 344 58 968 17 61 130 459 115 256 354 621 310 1214 712 1014 56 637 229 715 816 1195 1321 1365 602 670 557 865 288 623 1303 1340 834 1116 55 77 55 407 373 1022 378 1064 18 119 367 1143 366 524 49 57 375 720 183 227 11 51 43 745 327 329 850 1307 1287 1334 1059 1205 232 1084 245 395 858 1141 359 1112 362 408 161 893 370 470 773 994 213 1239 140 430 468 585 667 1003 36 576 42 749 49 188 28 134 17 218 66 500 434 1260 150 1251 258 435 8 55 22 182 553 716 851 1056 897 1247 463 614 5 19 605 878 205 736 111 957 56 1053 326 849 128 131 592 682 292 374 131 192 263 536 5 1321 886 892 108 612 141 987 280 1152 528 769 162 866 33 121 2…
Output: 23

Example 3:

Input: 1419 28 794 270 778 1 6 43 124 414 898 257 652 194 1391 113 1055 34 68 140 1094 11 16 141 359 169 688 297 999 62 100 816 938 45 204 517 855 360 1015 531 1151 1043 1415 2 36 430 1310 829 1068 577 857 140 508 639 1120 15 177 1071 1365 190 481 167 231 253 725 665 677 39 1128 670 1030 284 1160 114 632 19 222 940 991 161 462 88 1206 187 598 22 497 30 249 717 1229 1156 1332 22 324 170 1196 280 414 14 395 484 901 268 501 22 126 388 988 355 755 325 908 70 1140 807 1177 248 327 484 1312 359 1004 538 1169 516 1123 31 710 491 664 9 35 86 195 546 615 696 1034 1027 1089 106 291 314 518 35 382 346 1037 207 457 862 1387 2 10 37 153 138 211 920 1122 957 1093 298 870 28 261 5 815 635 899 702 1117 159 1231 240 572 267 1255 243 1334 302 807 428 1213 385 1153 328 551 366 639 432 763 1 1046 321 824 140 833 301…
Output: 24

Constraints:

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

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