CT32680

The Ember Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the ember dunes of Ashfall with crates of routes, and Brevin the dispatch writer must account for every last one. 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 <= 1182; 0 <= m <= 2364; 1 <= u,v <= n.

Example 1:

Input: 552 1766 268 497 38 186 12 121 311 459 56 551 395 475 283 545 333 415 73 162 81 196 6 111 24 46 202 515 268 481 115 324 39 140 75 282 122 398 168 398 51 362 158 313 121 384 195 421 232 262 220 338 390 518 153 240 193 331 70 406 216 442 474 520 199 337 181 339 181 255 53 528 84 532 480 525 270 320 254 347 79 101 92 468 360 437 139 273 297 356 34 241 322 375 325 340 94 280 28 537 241 380 98 356 188 401 100 288 70 150 33 307 479 504 435 537 75 404 99 404 66 198 247 338 349 385 339 506 25 379 214 387 164 259 225 392 106 166 346 435 98 483 11 453 211 404 430 484 11 221 361 459 195 460 274 384 28 406 63 478 93 226 112 264 289 507 2 40 249 368 218 478 392 526 18 335 38 70 243 471 204 284 250 272 36 476 284 405 342 443 31 400 284 434 92 160 342 517 1 56 149 167 77 282 237 371 60 162 206 340 14 171…
Output: 2

Example 2:

Input: 961 781 411 453 409 439 426 944 803 821 290 961 3 639 217 281 434 527 644 672 257 300 207 789 391 541 429 708 109 357 458 487 342 712 333 482 698 807 196 710 624 679 198 201 176 921 44 153 624 681 82 273 531 663 554 665 67 488 310 803 597 870 391 744 442 894 240 255 470 876 2 433 798 916 215 733 156 668 114 753 675 911 767 940 103 546 578 626 72 430 362 567 605 633 517 917 144 941 193 626 163 804 637 840 261 690 151 402 304 305 11 464 168 732 545 834 364 666 820 930 48 171 65 485 299 796 510 549 162 785 28 701 33 607 427 685 65 565 608 763 6 417 130 421 235 534 110 123 375 415 168 225 52 738 169 935 11 710 178 833 382 930 180 313 126 590 238 246 161 857 545 830 180 379 847 871 486 823 703 737 402 688 153 794 666 687 504 713 432 843 252 839 331 902 23 767 263 497 498 621 74 217 94 893 217 7…
Output: 238

Example 3:

Input: 555 956 127 278 98 263 64 368 233 289 177 550 56 551 129 188 65 506 192 301 410 518 57 514 146 292 168 381 417 552 230 252 412 435 298 394 181 395 338 400 282 500 348 541 104 224 265 501 173 481 291 333 235 407 52 260 207 539 416 514 65 518 68 550 225 272 233 364 130 195 38 435 314 413 435 500 377 465 406 431 2 403 98 245 32 541 93 173 188 374 451 525 166 170 243 538 209 338 245 338 21 343 210 463 300 437 219 245 332 379 51 261 287 339 304 545 139 199 388 504 176 510 471 504 367 484 271 502 93 389 209 321 164 207 238 330 442 511 213 254 363 551 46 365 137 261 259 303 310 318 22 33 190 299 517 520 31 348 204 242 344 554 247 413 62 354 443 457 29 447 81 278 73 108 208 255 352 524 282 530 120 253 114 195 42 237 447 536 143 492 198 490 23 341 348 442 288 302 25 96 228 271 355 528 87 443 89 276…
Output: 22

Constraints:

1 <= n <= 1182; 0 <= m <= 2364; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Ember Separate Camps - MEDIUM Coding Problem | CodeTikki