CT48498

Cobbler's routes Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the desert outpost of Sandspire, Cobbler the scribe keeps careful count of the routes. optimize the storeroom layout, every figure matters. 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 <= 2774; 0 <= m <= 5548; 1 <= u,v <= n.

Example 1:

Input: 1813 1476 1621 1750 77 1195 732 753 1298 1542 641 683 380 665 652 960 1287 1624 410 1140 813 1761 575 1060 1164 1707 215 1221 356 1133 840 1659 659 770 1117 1411 707 1207 1059 1774 2 966 414 769 179 1231 795 1421 1170 1295 213 1348 835 1631 241 697 540 1630 604 667 388 1364 112 913 415 1037 50 1255 1006 1352 309 1768 123 1212 510 1779 1136 1583 85 221 791 1790 544 761 393 1180 963 1484 257 847 398 719 754 1790 96 440 163 1531 56 346 1436 1483 82 130 433 467 572 1175 859 1549 1608 1742 997 1773 459 1421 793 864 721 724 676 994 606 1215 472 1598 65 516 974 1812 236 783 567 1174 246 1060 808 1763 766 1277 907 1145 914 1016 293 429 1021 1679 896 1383 676 1409 1031 1278 128 1652 376 472 33 718 1345 1601 1634 1643 770 826 1024 1108 121 135 202 1325 446 1725 865 1754 1342 1789 109 1713 246 1079 1…
Output: 471

Example 2:

Input: 476 1381 215 249 2 390 99 441 41 266 237 426 118 264 95 209 424 460 198 203 432 471 425 476 81 207 187 454 250 465 26 229 300 392 302 398 62 417 39 160 12 340 123 294 188 208 25 305 157 188 120 307 272 283 113 395 136 139 209 254 40 181 148 441 238 466 149 415 60 254 251 299 371 474 191 316 17 465 90 342 234 395 121 427 370 394 392 445 362 399 221 471 101 123 20 426 15 108 378 417 133 165 130 376 175 436 274 350 29 328 311 336 125 323 180 379 190 239 203 476 216 405 296 333 292 421 58 145 106 267 300 442 292 430 387 411 106 237 145 285 4 441 223 444 343 377 406 455 35 270 305 406 136 385 14 231 318 453 172 411 344 428 239 410 380 465 154 270 310 451 2 274 42 350 315 405 12 180 108 277 295 457 321 372 221 383 62 291 147 217 25 115 46 248 162 189 331 433 143 343 20 86 276 435 91 425 63 446 2…
Output: 2

Example 3:

Input: 1899 1267 1301 1632 895 1735 930 1788 46 186 21 36 169 1245 131 451 549 800 1060 1485 516 1487 928 1877 1500 1586 816 1223 1126 1707 1285 1830 184 1607 1039 1597 480 1298 203 1832 231 390 979 1387 317 1571 1593 1665 108 1801 15 1414 229 540 12 496 86 1113 1092 1661 1033 1793 272 1823 378 760 534 1600 1398 1541 441 788 1691 1869 1806 1836 27 813 1204 1544 581 1244 733 1841 720 1136 272 1362 281 1007 1444 1671 571 1579 569 1313 1151 1473 615 719 74 1466 953 1365 694 1185 1300 1324 1526 1598 1018 1436 195 492 745 1346 341 1659 1536 1664 869 1729 269 1394 969 1600 1142 1442 275 1635 118 199 1623 1635 671 754 28 1104 470 594 853 1393 1043 1485 587 927 137 1007 605 1759 228 1112 128 630 1127 1511 1729 1786 773 988 341 856 1235 1495 281 672 156 1787 1077 1669 801 1173 634 917 224 697 316 742 231 …
Output: 661

Constraints:

1 <= n <= 2774; 0 <= m <= 5548; 1 <= u,v <= n.

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