CT39632

The Separate Camps Beneath Thimblewick

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The chronicler Finn has been asked to forecast next month's demand. On the desk lies a long table of corridors readings. 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 <= 2847; 0 <= m <= 5694; 1 <= u,v <= n.

Example 1:

Input: 496 1614 191 307 134 391 370 420 8 229 222 469 214 414 37 346 56 225 212 328 16 422 193 203 137 141 282 379 208 361 135 442 4 171 292 459 262 313 46 397 179 361 25 328 94 288 287 474 353 383 1 413 169 451 290 375 250 261 22 33 109 184 131 160 18 204 6 382 444 459 142 389 1 299 74 234 382 442 231 448 192 303 58 161 195 222 192 315 129 186 34 39 368 459 24 300 347 463 4 60 86 203 17 365 382 421 352 355 81 464 131 227 49 331 281 322 188 190 141 365 51 112 139 283 20 295 112 151 180 428 460 467 168 453 106 146 270 332 118 455 347 488 142 380 112 344 424 430 1 262 152 385 171 352 117 388 169 360 248 430 31 61 103 205 130 197 71 200 17 146 223 389 173 316 127 342 109 207 182 352 210 294 444 483 162 437 65 459 262 277 96 484 410 496 177 466 196 346 337 468 262 310 221 346 126 177 219 368 219 261 …
Output: 1

Example 2:

Input: 1217 4250 361 858 74 1213 41 986 307 337 657 875 471 642 481 911 286 619 390 459 631 762 160 325 45 493 646 775 86 1150 262 1094 428 743 264 867 354 784 298 509 631 1216 706 745 633 672 472 752 456 971 894 1040 404 505 266 969 20 849 875 1045 357 573 93 582 176 265 366 711 708 739 542 754 826 836 259 785 127 936 405 1151 469 943 56 248 81 922 126 626 285 782 382 640 702 952 1059 1173 49 934 506 891 184 1066 235 1031 144 953 346 831 805 990 177 993 67 185 1028 1084 134 743 620 873 4 189 403 731 419 1056 251 1197 992 1125 862 1091 540 603 1106 1214 556 1193 22 780 449 924 485 492 96 267 329 903 528 1150 28 140 656 1184 140 312 215 1170 912 995 501 690 649 762 439 1167 726 852 290 375 1025 1102 538 695 296 1196 573 868 199 760 395 1066 472 1078 584 833 33 88 756 942 106 535 83 593 287 1062 17…
Output: 1

Example 3:

Input: 979 4162 302 886 339 934 313 901 781 805 1 956 618 940 656 899 400 441 598 717 283 865 65 968 215 955 735 948 684 819 599 825 251 812 232 527 931 950 168 630 505 966 90 110 650 875 256 872 130 612 162 462 138 901 174 894 277 519 202 595 799 921 603 854 163 352 702 746 346 526 625 838 527 946 582 667 515 874 801 806 220 486 295 938 319 822 163 432 239 929 379 859 156 510 447 842 770 938 759 873 431 659 799 849 218 715 237 523 380 828 670 919 371 507 24 391 778 894 807 856 78 470 133 502 185 634 166 728 427 758 776 830 338 441 554 942 5 640 240 889 267 933 71 362 80 787 617 833 251 367 347 755 492 886 491 526 76 558 669 782 33 306 559 924 152 503 320 449 246 432 133 240 307 459 262 461 258 407 580 849 122 428 453 666 553 597 94 453 506 872 130 686 182 820 438 731 89 172 893 922 637 661 223 9…
Output: 1

Constraints:

1 <= n <= 2847; 0 <= m <= 5694; 1 <= u,v <= n.

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