CT30060

The Separate Camps Beneath Misthollow

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Every season at the valley of Misthollow, someone must decode the foreman's shorthand notes. This year the task falls to Brevin, armed only with the canals register. 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 <= 812; 0 <= m <= 1624; 1 <= u,v <= n.

Example 1:

Input: 273 1439 137 232 75 265 19 88 126 270 21 35 131 166 17 105 8 46 45 196 29 215 38 59 235 238 7 259 175 264 10 38 53 111 122 124 47 68 81 195 72 258 74 76 88 97 195 230 64 186 88 156 87 268 149 244 156 173 3 135 46 240 2 66 59 259 84 163 42 103 34 264 209 222 14 39 8 130 216 222 132 205 169 173 86 177 79 187 180 234 88 269 95 126 130 238 104 192 134 180 26 146 43 66 84 257 129 213 156 213 45 162 101 117 138 244 8 174 162 247 130 147 157 231 130 221 31 148 60 188 98 261 78 156 128 187 50 71 121 240 16 224 200 244 225 272 173 270 143 256 74 185 70 214 225 269 101 269 146 150 71 260 131 213 27 34 126 179 62 168 11 38 196 223 157 221 101 186 158 231 164 197 108 258 232 254 96 174 20 170 38 176 37 76 22 100 99 268 108 193 3 214 146 169 38 60 109 177 179 244 135 194 77 120 59 82 69 136 5 18 152 17…
Output: 1

Example 2:

Input: 621 1307 375 578 183 555 332 385 32 528 402 463 194 251 50 448 257 457 86 219 247 555 180 373 277 445 199 425 71 364 224 407 352 483 409 415 45 296 70 215 244 404 20 438 205 398 380 498 91 127 188 263 100 217 38 187 520 546 25 274 7 462 196 556 128 240 589 596 11 24 334 601 35 187 64 128 518 584 2 556 465 509 23 411 61 495 477 565 120 569 69 442 457 619 246 508 385 500 134 429 220 300 186 337 264 321 165 437 152 528 15 557 365 528 44 476 173 293 139 387 30 563 66 253 80 479 175 581 239 504 124 390 302 561 44 176 242 353 340 534 445 601 53 205 7 203 56 205 80 88 33 505 164 559 81 582 53 279 337 480 161 311 312 354 218 323 27 355 20 232 112 164 329 415 230 529 119 208 437 441 54 597 39 337 375 550 69 191 141 163 41 416 268 569 432 569 249 368 110 256 8 56 148 194 114 621 192 599 40 336 372 3…
Output: 16

Example 3:

Input: 527 649 216 472 23 379 136 229 438 505 127 494 46 242 241 266 72 376 64 274 88 448 139 375 55 286 285 309 153 274 190 207 5 77 7 133 249 293 75 451 98 514 108 197 226 472 204 246 217 455 290 504 26 375 14 438 160 279 250 517 103 481 128 137 104 503 6 349 320 445 380 497 95 407 54 433 169 512 225 331 235 261 385 509 22 470 94 505 109 253 220 284 134 251 222 512 187 398 73 494 80 225 79 361 57 234 135 401 210 325 55 322 393 506 276 383 411 492 449 491 39 199 176 319 325 375 3 476 269 419 460 491 82 520 425 519 234 435 345 500 349 392 432 486 220 524 204 453 141 514 344 375 67 444 92 236 126 513 348 351 36 295 84 144 144 346 193 471 314 488 109 120 125 299 119 329 48 99 335 408 175 435 4 432 56 499 60 232 345 349 128 338 171 424 136 251 96 120 110 503 46 462 8 166 311 362 259 355 207 250 423 …
Output: 52

Constraints:

1 <= n <= 812; 0 <= m <= 1624; 1 <= u,v <= n.

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