CT50376

Trader's roads Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the heron rookery of Longlegs; Trader weighs the day's roads manifests and starts the calculations. 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 <= 2802; 0 <= m <= 5604; 1 <= u,v <= n.

Example 1:

Input: 1138 3939 301 309 178 435 423 916 778 1047 84 956 22 507 939 1027 121 971 898 1062 103 875 336 566 11 58 659 1086 525 679 421 1073 423 887 849 923 305 345 728 839 26 971 303 662 474 1069 26 344 182 929 563 964 524 902 936 976 837 1134 208 378 410 623 37 226 417 565 499 510 141 560 795 1100 220 985 324 586 133 1088 73 95 49 1104 8 107 207 798 23 394 205 350 528 1109 680 877 683 834 525 647 140 186 239 830 228 665 13 292 578 824 480 1002 867 975 166 702 683 1128 277 574 549 924 470 509 201 559 123 625 681 736 394 1062 431 1112 273 643 174 784 243 1082 74 623 398 719 294 830 481 630 45 1018 927 983 203 1067 477 629 286 988 642 1078 597 653 250 665 632 787 622 1138 253 494 39 567 309 832 226 910 602 987 400 916 30 499 202 1056 250 336 358 520 751 792 25 655 303 312 116 123 151 650 316 1107 137…
Output: 2

Example 2:

Input: 1481 3238 727 1010 345 566 150 1448 467 817 627 1413 53 269 928 1129 413 1224 479 843 459 1332 77 771 407 1080 569 1196 374 792 385 1110 353 915 504 1466 991 1157 871 1237 641 1105 26 710 529 1054 509 811 792 1058 958 1361 555 594 849 1355 75 1449 944 1222 218 704 99 1238 1384 1464 169 900 435 773 123 1122 223 755 300 538 1212 1342 18 33 31 202 258 710 1320 1354 736 1087 140 538 307 709 100 536 1083 1156 106 814 827 1467 329 573 357 1022 106 1342 1371 1372 90 368 556 886 1017 1137 326 747 1158 1408 75 1441 880 1319 689 940 499 963 237 849 345 1090 291 950 293 501 579 819 299 788 775 1433 949 1209 394 625 1150 1371 782 1077 240 652 1096 1276 592 639 1131 1447 1143 1210 266 1087 538 1087 268 610 1213 1312 44 615 137 616 925 1054 1080 1178 214 1462 108 318 769 803 1094 1220 862 1201 1206 1262…
Output: 20

Example 3:

Input: 1176 4574 119 394 88 618 159 1043 374 620 350 675 352 1099 287 579 970 1053 301 1118 270 285 389 1010 613 951 508 569 135 958 208 601 332 510 80 590 303 358 19 350 194 360 606 1160 616 874 752 793 9 1155 479 510 309 1061 957 1087 326 372 300 905 638 919 395 838 44 757 591 782 402 715 705 1033 453 825 15 477 938 1148 271 294 583 792 463 806 57 882 592 1128 907 1110 121 831 81 178 863 888 42 645 318 667 505 1130 558 913 661 715 957 1029 177 460 148 199 381 526 707 734 460 788 513 603 149 1054 1111 1170 242 531 659 803 55 797 60 614 16 701 591 798 242 1061 272 1061 285 876 243 583 268 317 452 1046 918 1084 369 615 280 497 134 367 244 1119 787 1157 467 760 212 722 930 1007 413 598 182 688 979 1038 368 501 814 1152 91 1041 161 817 362 987 53 845 921 1095 66 992 237 613 717 769 451 1020 339 354 …
Output: 2

Constraints:

1 <= n <= 2802; 0 <= m <= 5604; 1 <= u,v <= n.

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