CT41113

The tunnels at Shimmerdeep

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the opal reefs of Shimmerdeep close for winter, Hema must finish the tunnels ledger - one figure at a time. 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 <= 2135; 0 <= m <= 4270; 1 <= u,v <= n.

Example 1:

Input: 1857 1191 175 1834 344 1038 207 1522 656 887 751 1180 241 691 245 614 185 284 262 524 737 1847 107 1724 263 1616 950 1560 1060 1166 942 1802 164 1298 686 1267 83 506 12 784 636 1768 811 1431 145 467 940 1478 165 1312 710 770 753 765 50 1770 73 1235 1556 1710 431 822 1448 1521 462 1343 552 1187 310 590 1518 1634 932 1728 530 1671 249 263 509 1304 1020 1827 378 815 225 234 118 730 148 1373 726 1818 784 1289 664 694 201 823 441 1506 648 1353 738 1166 691 760 280 437 885 955 731 1630 1146 1643 1402 1797 631 948 424 888 475 748 1394 1831 106 579 625 1577 183 327 229 564 338 926 939 1170 630 684 13 1808 1124 1808 88 1776 1344 1754 119 172 1220 1679 610 968 1260 1288 225 386 451 1421 1074 1128 119 1263 357 849 963 1802 315 330 616 1812 1179 1627 412 811 893 999 1155 1672 174 1030 814 1841 1086 13…
Output: 686

Example 2:

Input: 721 3045 74 173 142 721 285 485 407 599 40 314 79 311 75 605 79 680 205 718 608 630 474 559 409 551 64 639 197 276 241 499 402 460 235 354 191 590 88 709 237 652 39 208 237 391 99 310 148 398 95 574 54 288 381 715 273 692 56 677 362 482 276 601 488 672 62 555 561 646 6 413 552 558 205 285 322 393 165 443 671 706 476 620 333 376 94 167 25 438 470 529 608 657 156 400 246 611 387 422 541 646 210 644 215 612 384 476 29 687 153 606 393 667 232 620 188 677 480 716 60 83 57 644 25 678 72 514 176 586 222 237 510 684 387 512 312 445 36 258 108 139 109 237 245 412 44 50 323 603 640 646 281 312 163 535 468 484 113 498 26 399 88 119 281 463 437 690 95 212 69 554 622 626 264 660 289 652 344 378 164 633 185 279 18 484 159 331 266 684 32 588 25 253 43 129 109 234 574 662 54 421 521 698 28 714 410 705 424…
Output: 1

Example 3:

Input: 1404 1850 791 1315 303 1231 391 954 129 926 1252 1261 31 1011 1176 1350 807 1050 496 1282 958 1176 311 1160 661 713 423 1054 130 210 215 453 36 1305 578 702 781 1289 656 1010 769 1245 169 536 944 1311 215 1337 459 1170 543 586 546 936 112 452 443 580 668 1045 603 1094 891 984 173 755 805 941 213 476 260 320 614 1370 679 953 298 648 683 839 544 745 338 771 30 292 299 1313 274 618 741 979 550 701 4 325 217 891 107 555 1206 1377 65 1202 119 710 364 844 1029 1395 643 1359 222 579 203 732 607 1047 73 461 319 1341 331 554 800 1148 388 1382 321 997 140 893 372 467 391 1101 414 614 197 502 1007 1227 767 1016 899 1201 452 1303 9 1281 70 684 909 1170 801 1336 291 1183 220 795 1003 1020 18 1101 29 391 435 835 583 1264 283 1245 220 630 358 472 165 316 394 1302 515 1088 46 809 1175 1277 1050 1146 1056 …
Output: 111

Constraints:

1 <= n <= 2135; 0 <= m <= 4270; 1 <= u,v <= n.

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