CT56759

The Separate Camps of the Wistful corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the cedar groves of Balmcrest, Botanist studies rows of corridors entries. One clean number will settle the guild's oldest argument. 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 <= 1050; 0 <= m <= 2100; 1 <= u,v <= n.

Example 1:

Input: 396 1046 124 337 83 225 91 151 265 395 5 298 132 277 230 287 101 337 121 356 15 305 117 333 225 267 118 289 77 272 174 371 111 312 2 4 113 320 329 346 205 393 122 236 85 170 22 146 40 382 133 247 138 389 182 353 144 303 65 271 146 338 104 331 294 311 141 153 196 258 154 213 162 302 69 97 7 327 123 177 268 338 141 222 150 154 79 177 308 377 24 132 242 266 193 343 90 103 51 52 108 130 243 246 357 367 201 340 140 211 174 382 112 121 204 393 282 323 53 286 169 227 14 140 22 222 102 121 222 297 16 351 242 388 44 382 43 271 23 376 126 283 153 309 63 306 361 384 137 213 250 332 61 293 108 115 86 315 79 247 45 347 5 179 234 235 42 396 123 356 309 370 12 55 192 307 57 309 184 217 120 323 176 290 49 217 25 242 33 102 167 382 103 139 172 259 28 111 1 224 128 156 41 156 320 358 87 225 10 231 34 149 13…
Output: 1

Example 2:

Input: 613 1015 358 385 212 565 429 449 420 598 288 396 196 335 42 363 568 603 7 517 161 162 66 311 292 592 4 423 341 503 188 459 391 581 33 522 435 583 580 592 162 588 132 346 149 405 41 357 269 310 326 508 87 295 27 487 217 584 54 552 101 538 18 531 207 209 177 351 182 296 421 500 347 549 333 365 33 260 4 112 169 557 151 475 388 389 159 383 274 576 148 255 353 553 234 444 189 551 507 602 480 496 190 263 397 475 230 250 235 429 429 608 123 260 114 457 239 280 43 433 495 519 97 168 294 325 268 581 57 426 365 409 197 285 173 288 514 569 94 201 175 204 172 445 221 265 31 383 481 601 404 422 542 585 528 533 56 466 442 470 262 518 13 152 176 365 76 541 22 208 554 608 469 604 74 102 398 501 5 480 34 210 213 525 85 189 1 612 429 477 220 393 116 199 256 536 403 548 168 541 310 441 112 346 216 343 212 45…
Output: 14

Example 3:

Input: 658 967 84 357 42 524 183 195 169 434 58 61 36 376 33 459 171 633 416 540 22 253 140 143 125 137 120 215 79 249 86 525 134 224 435 574 140 554 12 364 274 336 339 492 210 472 309 494 306 615 367 369 84 230 230 593 32 337 180 469 101 314 589 611 373 604 6 424 4 277 49 230 208 510 545 643 393 510 267 338 493 548 230 331 81 126 38 547 103 356 157 229 92 466 258 439 301 632 93 301 46 325 130 256 460 560 3 268 87 320 221 397 15 73 508 610 266 552 340 393 299 328 316 497 284 326 12 128 246 589 291 638 49 203 85 612 315 544 143 570 15 625 136 499 110 272 115 262 57 488 28 96 256 377 307 506 342 489 293 643 378 457 262 656 230 318 113 178 159 355 48 54 64 645 113 219 430 616 382 645 405 622 317 467 133 609 15 154 393 555 78 407 405 468 106 278 390 628 266 536 195 311 73 534 104 226 421 460 277 560 …
Output: 33

Constraints:

1 <= n <= 1050; 0 <= m <= 2100; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Separate Camps of the Wistful corridors - MEDIUM Coding Problem | CodeTikki