CT49718

Jarl's Painted roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The valuer Jarl has been asked to reorganize the archive shelves. On the desk lies a long table of roads readings. 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 <= 1487; the input is a connected tree.

Example 1:

Input: 1299 61 130 259 686 37 734 450 783 116 290 252 349 24 141 201 323 119 310 6 24 861 1235 1 53 276 831 104 166 1221 1261 218 363 33 48 52 845 459 1137 108 696 174 289 557 816 444 531 342 760 97 151 277 740 432 513 25 510 214 915 154 725 156 348 367 923 671 795 143 219 258 487 642 755 705 713 39 609 37 129 653 824 815 1024 14 164 209 340 72 1176 289 486 554 809 151 586 88 152 249 524 373 557 436 746 33 429 190 526 298 410 363 1281 632 1179 431 653 139 250 109 544 914 1288 1092 1105 148 536 128 358 670 805 655 775 654 927 440 641 413 550 50 67 888 1150 233 1228 580 703 107 933 717 1149 44 467 245 561 294 660 734 1080 271 600 249 1097 622 1068 1243 1298 620 932 968 1170 15 1212 295 665 11 560 533 878 699 710 92 279 275 277 303 430 95 186 546 1025 76 554 13 74 336 528 16 619 264 299 987 1232 574…
Output: 26

Example 2:

Input: 67 3 16 3 8 11 17 1 5 28 38 35 47 24 30 29 51 8 29 48 55 7 24 24 63 2 3 21 34 1 12 19 20 12 21 18 57 29 58 35 40 8 49 17 25 47 60 5 23 52 67 4 43 1 2 48 54 5 42 1 33 54 66 5 22 21 28 6 13 57 59 9 19 16 41 7 45 29 53 29 39 6 7 3 31 9 27 24 32 1 14 37 52 1 9 17 61 11 50 60 64 4 6 1 18 35 65 3 10 26 35 6 36 28 37 15 26 30 46 9 11 11 15 15 44 18 62 2 4 50 56 28 48
Output: 15

Example 3:

Input: 251 87 228 147 247 43 56 67 131 1 144 126 227 13 31 33 59 166 190 83 249 117 126 65 83 40 53 182 185 44 115 121 218 145 154 115 147 45 167 52 68 15 104 171 214 94 105 32 57 25 40 77 118 132 137 167 172 38 141 144 151 141 179 64 71 62 219 10 14 63 171 42 92 3 7 10 30 78 91 127 204 63 186 8 23 55 100 60 129 65 163 68 111 127 205 144 212 1 3 145 207 59 106 9 21 4 182 13 19 49 113 94 177 6 95 82 97 115 220 125 245 50 200 89 108 51 62 61 69 36 221 37 79 38 110 23 216 133 145 23 138 13 135 137 169 18 45 13 98 131 156 87 243 9 17 182 209 29 78 43 102 187 189 201 206 79 180 81 86 6 122 169 222 222 233 19 51 11 12 212 251 124 215 20 41 37 80 99 183 57 65 59 159 42 194 26 61 91 155 60 223 23 28 7 11 36 235 153 217 89 125 229 246 64 139 16 35 26 136 183 224 8 26 229 244 104 187 25 82 105 202 127 146 …
Output: 22

Constraints:

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

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