CT34834

Roving canals Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the rookery of Crowhaven. Quartermaster spreads the canals records across the table and picks up a sharp pencil. 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 <= 1563; 0 <= m <= 3126; 1 <= u,v <= n.

Example 1:

Input: 1170 557 386 776 189 520 18 484 616 705 349 1005 90 1100 234 1102 209 315 170 223 262 449 710 762 343 982 240 875 309 1107 89 299 508 906 863 1162 339 481 688 744 752 1026 248 373 240 980 612 1032 522 574 477 639 116 373 509 663 375 690 346 559 422 892 102 229 763 981 839 1152 331 1086 503 580 279 705 432 677 85 414 148 481 468 636 3 64 637 995 590 994 897 939 362 387 163 378 598 689 61 725 580 1130 426 814 1111 1112 185 248 167 177 18 27 832 883 906 1001 66 918 148 797 951 1006 93 937 430 787 453 913 85 1024 347 1138 806 863 439 954 124 924 215 346 828 1055 930 1091 220 841 475 1068 139 1118 238 536 884 1073 883 1013 458 777 173 665 8 642 290 785 173 813 457 1039 742 776 117 916 330 900 424 870 482 489 387 689 446 811 232 243 902 1038 71 206 392 1153 188 197 462 889 185 487 323 555 36 173…
Output: 613

Example 2:

Input: 622 235 44 189 63 195 246 525 34 348 179 349 530 611 138 254 429 440 61 167 54 336 463 529 543 579 145 454 412 540 313 347 156 216 12 366 38 267 146 215 239 546 165 351 84 597 421 530 9 509 18 422 364 476 157 440 259 319 3 194 47 260 6 35 373 617 96 378 258 399 48 245 239 597 473 491 479 480 107 514 118 398 297 499 434 586 124 430 368 516 107 533 211 284 161 225 131 603 193 426 2 412 118 421 81 251 85 510 225 335 89 359 75 408 42 244 433 447 63 327 11 270 284 465 183 598 420 569 148 182 303 309 525 589 391 413 190 558 326 441 185 240 521 560 103 107 96 362 216 243 473 558 122 216 201 555 122 574 187 484 320 530 190 491 15 551 376 567 163 478 173 190 127 349 20 520 359 604 123 287 92 474 519 559 353 590 244 425 319 412 275 499 18 527 6 112 200 613 482 576 287 556 503 513 8 235 47 213 197 20…
Output: 388

Example 3:

Input: 1291 2713 1138 1202 563 1060 704 1216 808 827 203 923 289 702 427 798 497 961 301 1130 96 444 968 1161 74 980 991 1218 65 828 133 1212 956 968 719 972 1145 1147 863 902 399 1169 440 1179 28 793 372 467 138 530 69 478 386 1251 575 802 109 1129 259 638 321 452 408 890 577 977 50 916 37 293 352 575 142 1091 358 365 240 880 420 876 249 467 73 1035 413 647 109 203 189 953 701 916 262 413 1103 1162 944 1215 232 908 177 495 562 991 65 183 434 896 697 989 229 658 801 1053 130 404 264 1033 253 754 673 963 564 656 270 1009 141 288 145 320 772 879 6 88 791 897 156 1271 565 585 1129 1205 449 909 1145 1274 25 680 447 1130 685 932 37 812 164 1219 840 1020 747 1107 454 1161 481 1026 102 1222 50 575 786 800 737 1065 270 312 489 1237 636 1101 226 494 167 271 49 1279 590 1285 1143 1234 1106 1139 831 972 577…
Output: 29

Constraints:

1 <= n <= 1563; 0 <= m <= 3126; 1 <= u,v <= n.

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