CT38960

Vigo's Jade tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the ivory gates of Alabast with crates of tunnels, and Vigo the cartographer must account for every last one. 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 <= 3406; the input is a connected tree.

Example 1:

Input: 1480 1296 1376 362 432 876 1270 566 1059 307 847 1216 1263 83 145 262 304 40 779 36 644 754 1306 225 959 391 711 1202 1320 633 1413 99 100 6 1442 43 549 389 759 20 636 1003 1336 672 793 96 127 672 1368 340 674 58 120 12 143 1112 1225 69 474 168 354 10 416 591 844 169 445 264 546 8 379 124 1332 53 369 31 191 108 775 541 623 842 1102 108 123 146 179 1010 1335 273 469 17 28 567 764 332 1145 100 168 198 715 15 196 48 97 87 112 392 1137 11 56 144 441 279 963 475 537 930 1406 1065 1193 818 1161 360 1339 901 1307 234 888 184 964 424 530 1021 1134 190 289 439 522 221 258 567 836 144 315 9 513 2 7 597 973 273 861 197 248 265 1428 776 1180 941 1317 426 859 538 707 66 1467 409 1242 373 440 268 594 301 881 901 1366 26 637 248 347 697 746 268 1342 156 1410 256 305 1 752 649 1126 539 1437 142 610 288 29…
Output: 25

Example 2:

Input: 2121 328 2102 396 959 201 1543 191 1882 4 1607 46 838 917 1244 251 444 1238 1545 225 271 825 1538 203 1383 515 1948 711 732 307 341 251 454 575 685 1149 2012 1092 1697 164 424 297 321 577 659 603 824 168 861 405 975 506 2091 397 519 475 1901 98 1265 205 1220 88 1646 327 386 108 286 12 13 418 708 298 1473 1103 2103 281 307 26 834 95 147 578 1710 278 508 222 524 445 520 82 256 388 1502 135 1506 92 429 405 1391 262 1077 803 1192 1014 2088 1309 1365 241 296 105 279 70 767 84 426 575 648 50 1548 1126 1608 704 1919 577 856 1302 1852 95 328 147 599 1023 1063 972 1333 777 1056 55 246 316 537 219 397 1010 1934 33 225 610 942 1119 1642 369 710 131 238 149 528 136 1523 469 1445 118 641 931 2116 55 443 44 241 247 2072 15 400 194 1246 455 772 33 453 54 203 461 798 305 815 530 541 797 840 1003 1234 9 17…
Output: 31

Example 3:

Input: 712 78 237 225 436 277 541 144 562 16 294 260 302 166 377 8 15 81 464 164 474 24 396 263 688 92 201 446 600 299 314 7 34 8 252 245 415 266 434 6 91 65 256 127 581 200 219 24 407 269 653 559 692 94 184 188 480 190 227 425 633 89 319 299 371 25 90 255 312 156 321 56 308 405 468 149 605 64 710 274 429 434 514 80 265 43 204 52 657 390 664 392 502 185 372 423 475 195 409 142 440 203 257 2 124 4 10 5 114 105 346 381 681 11 40 51 56 4 216 378 463 184 503 20 27 95 547 30 78 2 694 138 531 599 704 51 380 456 534 531 629 176 315 264 332 146 420 379 456 154 205 328 512 13 64 145 259 139 386 158 575 73 378 193 267 385 568 74 660 115 404 187 665 1 26 183 484 202 238 82 160 219 557 22 188 144 329 60 222 64 157 195 428 19 33 109 129 440 586 24 300 119 540 102 106 180 310 12 583 44 166 87 326 133 175 186 3…
Output: 21

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Vigo's Jade tunnels - MEDIUM Coding Problem | CodeTikki