CT48862

Jatin and the Longest Trail

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the northern keep of Frostgate pays by the answer, and Jatin intends to earn it. First: the full register of bridges. 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 <= 1284; the input is a connected tree.

Example 1:

Input: 913 455 847 10 15 225 364 167 657 7 808 436 499 7 45 27 146 182 727 141 238 477 802 106 193 387 540 38 103 288 655 296 585 15 75 63 483 83 253 590 654 394 679 215 725 246 599 11 32 271 731 115 259 9 16 283 299 128 198 178 570 91 613 44 388 560 568 22 107 180 314 586 746 75 376 832 860 489 743 170 179 369 580 314 339 432 492 686 874 13 169 134 139 23 26 156 285 301 762 71 310 877 904 75 195 421 771 375 515 14 21 443 583 629 786 264 292 310 502 7 503 764 832 83 121 3 220 137 287 495 638 368 379 191 521 22 449 145 334 732 765 212 737 247 288 1 110 270 862 14 66 348 609 51 131 47 488 283 596 605 842 569 631 165 267 369 890 80 541 292 831 817 897 411 551 286 347 175 716 248 328 206 399 416 468 553 709 205 619 133 763 125 283 659 772 188 421 23 333 546 732 3 393 68 313 407 693 441 700 422 604 27…
Output: 30

Example 2:

Input: 432 59 157 375 387 61 267 128 255 221 263 46 246 19 92 305 413 23 287 171 360 35 40 68 209 120 162 16 21 99 281 3 193 301 337 245 279 136 238 124 331 2 38 36 409 17 259 93 233 109 349 108 187 84 150 27 406 99 109 1 2 169 217 308 320 45 76 5 41 126 250 45 53 55 68 172 256 69 74 48 202 54 131 35 58 256 345 78 340 99 129 302 351 202 239 102 347 7 50 69 200 119 207 24 326 209 393 16 88 29 39 77 288 302 372 74 215 14 78 59 71 4 16 6 36 11 31 8 12 235 427 186 252 71 235 229 247 15 348 83 113 389 423 32 294 185 362 36 115 77 87 62 179 122 192 177 327 49 62 98 107 125 261 6 13 16 19 73 125 64 420 13 290 61 216 70 296 58 127 26 55 247 324 28 94 145 265 87 292 91 286 68 153 37 46 109 355 9 249 103 291 11 132 95 322 117 139 185 328 134 224 207 412 82 121 227 332 31 174 224 225 47 147 32 371 5 18 250 …
Output: 20

Example 3:

Input: 706 12 15 29 62 138 302 81 624 44 108 159 583 60 161 81 489 61 430 17 24 38 90 9 333 29 151 125 127 1 11 162 490 54 72 49 95 3 21 106 268 428 470 245 468 11 91 138 460 317 418 270 589 39 128 110 180 298 558 376 563 35 121 286 689 59 192 493 683 320 617 508 548 11 56 337 506 416 519 49 169 12 529 150 264 193 658 30 75 4 28 31 97 72 136 285 504 101 123 10 144 57 86 87 201 230 235 331 355 12 63 33 382 570 577 132 465 17 510 151 495 255 340 157 283 434 485 413 673 6 170 64 412 527 665 298 359 122 388 193 271 89 119 440 600 3 26 105 645 70 147 301 383 162 259 246 327 140 628 24 199 104 116 11 25 505 521 76 567 189 257 108 443 113 690 381 461 4 5 177 269 518 662 593 688 3 142 116 527 23 541 317 582 27 47 179 385 13 23 93 211 20 162 235 445 84 212 171 473 332 366 112 319 2 8 194 275 242 581 67 31…
Output: 24

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.