CT55448

The Verdant roads of Anaya

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the gull cliffs of Screech Point with crates of roads, and Anaya the factor 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 <= 2405; the input is a connected tree.

Example 1:

Input: 1422 29 162 837 1188 323 640 160 375 867 1130 420 622 318 815 662 1345 802 1163 242 953 81 244 32 701 84 94 718 1114 449 959 68 794 430 667 399 432 210 261 137 458 282 464 1059 1340 707 1115 299 546 116 397 48 169 24 921 149 396 183 188 528 565 259 1342 88 130 6 502 140 1285 118 588 7 31 70 200 478 816 715 787 556 843 424 713 320 355 359 845 43 944 302 942 28 71 109 278 56 422 37 1041 374 936 142 1141 308 1258 113 342 1 136 840 1025 120 344 90 729 112 412 11 854 833 1077 767 1386 142 181 312 682 306 777 298 629 317 750 221 801 190 393 239 274 85 392 5 24 178 559 44 1055 100 1002 7 8 5 70 259 494 150 970 371 1045 694 913 256 451 110 425 211 641 355 702 663 973 58 447 485 1310 187 740 224 1112 1036 1074 730 1125 436 492 250 1007 85 442 226 328 88 722 110 467 204 237 357 445 232 325 329 526 6…
Output: 26

Example 2:

Input: 1801 544 1289 1050 1370 729 1489 608 1090 695 912 86 153 896 1366 230 1695 401 751 99 330 621 1558 588 1756 995 1430 538 558 396 617 667 697 822 1418 937 1612 615 1083 194 209 1536 1729 35 369 940 1164 157 1209 979 1513 453 586 384 959 316 679 1122 1606 615 1508 179 1066 41 77 1305 1609 30 227 60 96 66 245 256 875 710 1113 120 1620 709 987 314 395 354 393 875 1605 287 595 719 1499 723 1241 22 1104 7 70 282 421 1282 1537 333 1763 139 821 290 622 582 683 44 380 898 1421 161 1211 497 755 449 574 11 26 133 598 403 570 726 1189 876 1043 341 923 809 1168 96 198 608 1154 708 988 60 879 42 858 32 207 32 1033 1076 1470 1004 1025 633 855 1386 1768 1098 1363 258 1615 6 1448 691 1207 85 504 70 90 37 627 241 510 32 701 596 1713 42 181 702 1029 25 351 91 208 9 777 49 84 714 851 145 377 406 657 45 1375 2…
Output: 29

Example 3:

Input: 1767 71 169 728 1107 186 195 1121 1554 119 1263 1002 1347 1122 1443 891 1001 94 421 440 886 235 247 692 744 173 249 339 507 269 556 5 307 1013 1329 231 1230 527 747 702 1204 106 227 26 50 238 258 34 926 401 909 365 1748 266 525 785 1095 1374 1468 247 1030 701 1058 765 868 397 1198 502 778 956 1258 262 958 28 626 278 347 16 69 29 979 563 915 8 541 226 335 398 1182 14 35 230 903 715 1083 77 106 218 223 813 1212 275 300 339 1457 153 1179 157 215 53 111 127 1217 73 1550 269 570 270 1295 2 159 429 1239 299 1290 470 545 816 1735 661 1740 511 1045 372 655 555 1201 1013 1296 1043 1674 397 889 29 62 328 436 389 730 660 731 14 21 337 378 1096 1402 145 339 214 1305 65 1716 406 988 354 380 844 1206 153 185 855 1284 1321 1615 169 1671 629 1683 1261 1455 1132 1766 169 777 19 817 1465 1719 240 882 493 10…
Output: 30

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Verdant roads of Anaya - MEDIUM Coding Problem | CodeTikki