CT31168

Ranger's Separate Camps Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Ranger runs the apiary at the steppe camp of Horselord Plains. Today the books show a list of corridors, and the numbers must be worked out before sundown. Task: An undirected graph has n nodes and m edges. Print the number of connected components. Input format: First line: n and m. Next m lines: u v. Output format: Print the component count. Constraints: 1 <= n <= 645; 0 <= m <= 1290; 1 <= u,v <= n.

Example 1:

Input: 429 24 106 422 81 415 83 352 69 124 162 372 177 393 349 369 51 166 164 320 241 315 36 330 43 102 253 268 18 232 284 417 200 272 102 281 243 371 104 115 404 409 204 348 145 188 4 28 108 155
Output: 405

Example 2:

Input: 186 1158 62 177 53 70 9 128 21 135 121 140 65 118 107 182 35 69 70 135 25 137 11 33 58 60 3 178 128 173 9 84 69 105 131 135 135 138 120 131 34 41 79 158 7 161 45 52 99 120 38 117 139 144 62 80 17 99 17 24 10 72 16 48 88 147 47 103 59 83 70 133 24 48 4 53 64 162 19 24 163 168 87 116 75 143 18 23 17 103 22 136 37 121 61 106 60 120 105 169 66 88 165 177 29 149 148 181 98 157 62 83 9 162 48 151 33 79 15 64 130 154 15 184 108 133 29 46 141 166 16 179 4 99 169 186 21 44 30 166 21 80 1 145 28 78 17 95 101 180 115 155 42 181 124 130 96 164 120 180 56 59 35 129 116 150 71 155 57 132 170 180 19 95 124 174 83 172 172 185 36 125 128 154 107 144 8 174 32 70 116 156 34 160 11 90 70 93 81 168 3 40 13 157 141 178 46 82 32 139 93 166 20 76 165 185 61 68 110 148 100 173 10 121 25 71 108 152 11 55 1 154 121 …
Output: 1

Example 3:

Input: 463 293 224 282 119 398 17 105 281 431 221 348 87 94 224 371 146 278 326 374 432 456 393 438 67 120 135 242 121 148 365 448 165 340 186 326 5 203 204 315 25 237 29 189 89 218 177 318 6 19 12 110 27 263 227 455 3 316 35 216 249 329 108 192 120 346 32 391 43 329 161 267 4 284 22 409 287 354 223 310 28 412 159 244 223 322 26 419 291 316 274 399 43 250 35 403 98 117 334 427 201 246 239 410 16 135 395 401 40 352 19 352 378 420 129 450 181 455 193 370 179 422 73 223 81 172 315 459 376 417 74 293 235 375 144 184 166 191 4 212 113 393 96 153 186 266 24 181 316 404 274 278 80 422 3 293 318 440 78 198 240 409 35 454 191 436 335 463 114 202 403 434 194 295 244 333 71 393 220 332 45 358 281 404 120 301 343 452 81 379 75 200 231 438 81 415 215 299 188 202 157 411 75 202 133 329 193 270 83 448 28 269 17…
Output: 177

Constraints:

1 <= n <= 645; 0 <= m <= 1290; 1 <= u,v <= n.

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