CT45466

Nils's corridors Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nils runs the observatory at the saffron fields of Marigold Row. Today the books show a list of corridors, and the numbers must be worked out before sundown. 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 <= 1737; 0 <= m <= 3474; 1 <= u,v <= n.

Example 1:

Input: 1687 995 6 590 9 571 423 1314 1127 1501 843 1511 277 652 46 1292 455 825 1161 1629 54 288 1389 1659 343 692 150 1296 200 1607 147 1609 1138 1549 143 1140 245 570 631 1222 456 822 292 418 43 573 190 213 304 1563 288 505 380 950 814 1356 572 1336 323 850 685 1141 6 1023 425 1631 23 156 610 1139 9 496 698 1051 1016 1192 870 1322 1203 1609 158 857 444 1236 925 1158 592 1296 388 1462 101 654 1040 1183 110 763 305 1640 813 1153 761 1480 584 1284 257 1011 1044 1084 308 1532 336 504 1068 1448 648 1507 918 1344 644 1395 430 547 157 1234 878 1671 325 1164 260 1330 332 1253 190 1092 396 1210 574 1364 21 786 680 857 115 256 689 1169 1225 1331 140 229 406 1375 422 1491 411 650 266 1600 55 867 169 550 932 1458 1007 1131 457 1381 883 1462 263 551 1268 1611 892 1258 504 1086 780 923 18 323 382 1511 880 16…
Output: 695

Example 2:

Input: 1157 2791 55 998 424 974 221 681 295 902 583 981 132 687 721 935 523 1101 232 791 715 1083 285 1060 500 1040 324 512 873 887 173 879 467 915 126 735 515 1018 485 820 655 1028 767 850 473 503 189 363 408 612 580 888 664 918 458 1133 454 1009 327 990 33 698 468 913 267 435 734 1134 783 834 551 1095 427 528 425 494 673 1107 656 756 74 894 63 99 796 1109 306 878 229 514 181 683 26 1119 40 393 180 209 163 434 240 400 443 932 511 1117 612 803 191 664 187 1012 704 1088 65 207 974 1098 968 976 39 886 703 912 2 677 376 1129 501 935 28 80 332 769 135 396 756 980 414 1071 74 1024 667 890 450 1075 111 1116 30 204 52 245 517 928 664 953 248 293 665 752 115 1088 353 509 915 1112 505 763 474 495 781 904 537 1125 247 847 103 213 57 825 673 931 183 902 152 536 11 607 289 665 519 1136 320 457 296 534 187 48…
Output: 16

Example 3:

Input: 1545 1886 1069 1427 102 1399 885 1078 2 1226 294 870 97 1010 946 1070 1271 1472 299 1044 260 847 943 1466 1230 1456 824 1304 240 1155 479 756 673 768 146 940 581 1164 596 1032 215 896 194 223 713 1319 380 1004 483 810 707 1381 390 1071 140 200 602 940 1360 1409 1053 1198 257 713 1210 1545 63 1480 93 1348 451 651 1297 1512 50 1306 587 1148 961 1511 461 1408 505 843 1294 1297 1163 1399 823 984 155 896 357 1464 799 823 109 847 94 960 121 1445 301 599 165 1160 139 1086 1242 1259 312 1462 171 627 124 1001 688 897 875 995 776 1398 364 602 725 1517 51 1385 48 1122 66 346 489 967 78 1252 1012 1438 789 1409 767 956 416 889 36 510 16 1043 151 935 163 1263 469 1044 725 1479 391 775 464 778 436 891 178 793 411 1508 436 717 307 979 328 1293 809 928 30 1141 466 1074 161 398 78 971 229 965 248 448 520 11…
Output: 152

Constraints:

1 <= n <= 1737; 0 <= m <= 3474; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Nils's corridors Separate Camps - MEDIUM Coding Problem | CodeTikki