CT44188

The Separate Camps at Bloomglass

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the orchid house of Bloomglass with crates of roads, and Finn the quartermaster 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 <= 1769; 0 <= m <= 3538; 1 <= u,v <= n.

Example 1:

Input: 621 2927 50 93 243 460 395 537 150 580 130 487 14 97 106 582 477 518 372 547 358 504 402 462 469 503 142 442 71 118 234 345 144 239 441 448 376 592 122 586 171 506 168 323 99 349 73 499 253 486 101 356 49 217 37 98 212 232 412 583 94 285 274 558 93 190 239 349 64 192 234 578 146 244 476 552 75 189 258 364 15 412 32 154 75 291 39 170 158 233 198 363 218 264 387 392 326 410 378 389 281 502 290 440 86 585 220 246 338 588 520 600 294 532 390 529 317 384 96 102 406 491 313 322 93 434 202 356 342 376 365 599 589 590 276 290 271 513 65 347 315 558 93 308 231 403 504 596 182 224 73 358 38 409 340 467 252 514 102 181 169 236 500 562 418 540 191 530 16 488 133 543 46 117 394 460 271 423 202 584 380 531 161 532 336 352 365 382 300 559 211 415 471 525 205 527 266 552 220 348 112 611 58 362 248 586 216…
Output: 1

Example 2:

Input: 1108 1543 719 846 153 646 17 140 475 1035 686 1082 611 656 912 988 20 879 486 934 352 947 618 875 591 976 337 351 449 531 508 822 969 1066 546 997 546 674 270 848 207 900 457 900 81 332 213 491 421 780 147 634 595 860 399 906 121 895 200 706 123 291 413 705 342 689 660 983 478 1083 267 953 547 794 574 1100 350 665 152 533 604 734 660 806 654 938 361 593 438 684 217 808 107 417 2 274 333 1066 824 827 511 838 204 1101 428 1013 509 975 82 471 306 671 526 999 390 967 580 626 87 769 129 930 54 138 53 339 267 849 442 750 276 307 120 371 476 956 728 1032 284 377 339 683 391 717 516 701 171 709 559 830 433 870 232 244 1059 1104 238 553 545 752 293 377 333 966 11 891 903 1093 954 1063 42 640 133 309 352 502 48 471 677 1105 37 248 475 832 689 744 760 1035 313 928 558 830 497 1076 512 990 308 720 103…
Output: 72

Example 3:

Input: 83 105 49 59 6 44 32 39 1 69 5 25 18 72 16 59 31 57 32 63 42 49 7 64 11 12 55 69 49 54 35 67 7 76 11 38 28 46 29 32 22 59 6 69 27 64 44 69 2 19 4 72 1 7 34 71 49 76 5 17 4 65 4 82 23 82 18 25 26 57 13 35 13 73 42 64 31 43 1 64 25 27 68 72 24 63 11 16 48 53 18 80 32 55 57 70 7 34 44 47 10 29 4 57 15 21 22 38 14 25 25 44 43 63 39 71 59 68 64 69 27 76 8 78 11 41 39 56 10 36 46 71 21 45 37 62 35 57 51 67 5 83 77 79 23 56 31 81 17 43 49 78 64 66 58 60 56 71 17 36 21 46 45 65 28 60 1 81 65 72 12 19 25 68 6 67 36 62 44 57 58 79 41 50 12 30 4 56 24 31 6 23 14 43 3 78 23 67 28 72 42 54 32 36 20 42 15 83 7 57 43 75
Output: 8

Constraints:

1 <= n <= 1769; 0 <= m <= 3538; 1 <= u,v <= n.

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