CT43811

The Umber tunnels of Zoravar

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the zephyr cliffs of Galeholm pays by the answer, and Zoravar intends to earn it. First: the full register of tunnels. 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 <= 2466; the input is a connected tree.

Example 1:

Input: 1220 25 1137 322 719 142 556 283 497 333 1069 336 1168 90 171 102 887 32 373 793 922 653 991 57 118 443 1077 59 342 459 810 65 634 806 1064 718 1054 157 374 578 974 782 1148 724 875 105 202 163 401 215 228 9 172 15 411 456 919 145 918 279 850 218 333 32 205 64 127 220 312 133 221 487 552 397 450 683 1043 7 19 322 412 35 57 25 240 643 671 643 720 44 1080 37 81 297 701 115 419 513 998 35 75 71 301 54 164 122 307 878 1107 257 464 44 832 10 876 376 1044 254 347 396 574 108 668 414 528 64 257 63 155 35 106 820 932 908 1089 228 318 48 1161 643 845 206 489 332 873 302 567 18 486 1120 1145 606 1075 133 743 39 180 390 716 2 499 150 939 95 241 291 880 225 260 443 566 340 465 435 1021 77 227 875 1083 605 799 87 117 21 102 238 363 423 1183 845 1079 323 635 695 910 15 73 585 870 96 105 355 826 64 200 2…
Output: 27

Example 2:

Input: 473 41 49 127 169 232 297 154 259 235 283 319 349 16 79 17 123 43 90 62 162 154 173 43 439 340 415 20 134 11 257 302 399 263 407 302 421 23 286 18 61 145 195 60 206 299 367 2 65 22 107 235 309 39 56 3 4 164 279 278 364 210 219 194 272 78 132 39 178 71 334 80 157 13 152 220 353 51 117 153 262 182 190 25 42 10 296 225 295 65 103 51 168 88 139 82 196 19 66 246 458 198 468 9 21 159 331 132 419 47 60 240 245 18 275 15 16 50 240 75 201 146 345 15 39 77 284 51 108 330 358 323 437 340 356 3 46 408 466 130 225 366 405 217 450 391 436 80 377 83 86 431 448 18 146 314 402 9 31 7 93 119 369 18 22 383 454 86 228 98 154 110 243 87 125 41 224 11 12 49 385 80 187 184 218 415 455 253 391 247 400 11 13 172 252 297 352 137 373 154 426 252 253 80 89 4 5 78 314 71 112 40 73 78 285 98 258 15 403 352 372 38 131 2…
Output: 22

Example 3:

Input: 2135 147 361 323 503 128 276 955 1052 15 1047 588 635 54 1090 37 46 527 854 409 413 1288 2114 1420 1596 156 902 743 1295 363 1754 374 1500 518 1709 21 156 890 1388 248 375 748 1402 1166 1541 386 1466 524 1819 1248 1772 503 1458 289 316 474 1833 148 669 63 101 258 552 443 1637 969 1261 1815 2104 906 1105 157 1268 103 116 277 1987 1660 1696 427 1143 1589 1876 636 1801 512 2099 201 685 1076 1424 1360 1593 1249 1925 14 48 879 1339 643 717 361 930 126 563 216 812 936 1253 137 524 1184 1289 492 1701 5 54 34 891 433 513 10 106 516 1144 75 1950 213 2105 347 764 975 2050 822 1588 448 502 144 707 7 133 1239 1827 757 865 183 417 339 762 984 1236 1067 1245 84 130 203 605 126 679 880 1519 100 332 357 1233 1044 2116 2 15 96 146 29 212 1794 2045 167 424 1298 1669 233 1204 434 879 302 1799 583 876 614 934…
Output: 28

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Umber tunnels of Zoravar - MEDIUM Coding Problem | CodeTikki