CT32656

The Whitestone Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the alabaster quarry of Whitestone with crates of bridges, and Rune the chronicler 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 <= 1452; 0 <= m <= 2904; 1 <= u,v <= n.

Example 1:

Input: 718 965 153 400 436 698 82 681 436 489 216 317 199 718 70 397 250 498 157 436 174 277 302 516 311 433 45 112 519 630 7 138 411 639 55 168 500 638 498 546 632 705 337 532 163 355 465 701 273 501 131 574 45 187 449 458 95 711 4 181 61 201 479 586 123 443 225 606 96 128 56 450 155 668 387 444 112 688 113 363 227 361 278 526 178 594 425 547 552 675 215 572 216 661 101 281 563 575 547 701 113 129 45 214 605 676 264 399 28 685 213 636 226 652 46 353 150 277 393 471 337 399 319 334 476 665 293 336 69 544 592 640 151 592 303 628 66 105 191 219 427 462 132 710 233 523 231 568 397 457 128 683 213 226 170 402 89 197 246 486 388 508 566 717 121 297 13 627 36 152 189 559 149 245 352 632 332 388 220 262 20 614 326 674 207 484 191 458 228 276 401 561 82 272 149 343 453 501 342 628 68 310 38 424 303 421 6…
Output: 52

Example 2:

Input: 1031 1910 614 891 597 757 433 701 119 246 267 420 291 991 144 807 305 820 212 847 70 559 48 597 131 482 623 977 372 606 633 661 435 909 388 784 330 467 862 883 231 633 326 916 581 695 904 1006 265 821 94 814 947 975 113 295 262 919 37 464 140 317 889 940 511 644 423 755 188 1030 298 857 549 966 464 712 842 1028 250 944 696 969 429 973 190 518 504 599 283 800 671 993 368 900 491 715 661 790 300 976 68 455 325 435 144 948 368 736 491 849 326 890 292 940 37 108 314 461 260 1025 161 234 44 924 44 466 676 895 318 906 315 405 473 755 189 457 417 473 552 990 77 894 275 975 322 823 409 411 113 619 782 976 385 741 240 423 392 931 750 869 90 610 609 918 370 593 673 960 663 760 513 929 792 853 284 559 470 892 478 562 408 690 327 556 125 318 91 304 611 1023 247 739 260 838 644 669 264 654 164 954 500 …
Output: 25

Example 3:

Input: 1324 1772 53 199 820 1190 452 709 640 1303 1017 1317 690 749 158 817 172 1240 497 1122 534 864 139 276 77 945 309 991 108 126 338 351 1139 1196 535 685 84 734 459 838 664 1088 243 876 659 990 731 1159 397 1099 271 1180 366 739 453 862 230 1142 124 1308 352 1220 450 1217 17 1097 304 522 617 1283 853 1095 1103 1258 698 1239 135 494 712 877 632 750 740 1149 481 590 369 437 395 855 1075 1303 344 951 1113 1263 487 1080 382 1144 197 1164 612 1139 226 541 444 956 192 583 171 1123 511 1021 820 1098 1265 1301 326 399 804 836 1162 1250 443 519 510 1228 305 725 646 849 303 695 149 624 1028 1264 248 989 583 1245 28 711 79 1076 489 851 897 966 5 1248 962 1029 130 856 533 798 114 758 486 995 930 1229 1077 1263 520 1234 333 689 52 800 187 1176 1102 1168 296 1022 28 619 269 1085 175 1145 138 359 235 1286 …
Output: 111

Constraints:

1 <= n <= 1452; 0 <= m <= 2904; 1 <= u,v <= n.

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