CT33698

The Separate Camps of the Ruby corridors

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The ledger master Zaid has been asked to schedule the next expedition. On the desk lies a long table of corridors readings. 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 <= 1849; 0 <= m <= 3698; 1 <= u,v <= n.

Example 1:

Input: 1750 1148 931 1513 911 979 995 1091 17 1417 480 571 867 1573 781 1548 600 641 553 1630 936 1227 925 959 1391 1507 611 1719 88 611 25 1041 236 1388 971 1304 868 1030 116 1442 380 1601 14 1694 457 1224 1624 1744 29 368 333 1628 861 1150 648 1363 654 1433 75 278 365 1701 1287 1308 1260 1529 578 955 84 1434 1019 1171 686 966 1151 1459 155 769 1096 1317 1108 1672 831 1363 189 279 532 559 300 1209 133 1689 1097 1278 894 953 950 1008 250 1169 1144 1407 507 1494 661 825 1039 1041 142 759 999 1444 602 1341 130 447 361 551 284 1070 79 203 1429 1629 726 1350 1110 1248 186 1737 314 783 942 1144 827 1032 1176 1733 1018 1733 830 1425 520 1096 1045 1058 855 1417 516 724 33 770 687 1703 419 714 546 1326 226 1208 491 1469 6 223 131 1142 447 1251 1118 1669 1574 1742 448 890 369 1634 628 1487 559 636 573 844…
Output: 616

Example 2:

Input: 669 2512 244 523 256 437 455 571 216 357 142 342 565 663 149 313 16 52 285 292 301 539 136 442 510 636 347 390 475 582 178 558 18 219 304 342 206 411 29 638 302 330 108 421 161 353 33 104 321 388 100 541 146 340 14 490 28 135 42 350 184 642 217 631 29 338 234 343 56 183 238 526 446 663 252 374 53 377 437 644 112 216 7 256 181 392 456 578 5 523 277 442 125 252 82 415 266 520 116 640 189 475 21 427 392 469 107 238 497 653 506 649 362 415 465 656 312 343 229 507 163 652 134 371 188 562 131 424 426 455 253 590 159 577 127 572 217 399 220 519 129 360 216 328 524 609 122 277 353 523 210 626 58 137 81 629 566 641 226 248 356 419 31 240 486 491 89 637 234 430 61 363 169 439 556 561 158 248 459 563 204 469 380 517 61 643 183 492 36 218 418 608 40 597 40 268 270 502 515 655 123 159 291 514 22 121 18…
Output: 1

Example 3:

Input: 1751 2777 643 1221 99 572 908 1522 273 1081 570 611 338 801 510 709 672 1251 233 1294 2 1242 305 1150 60 108 562 799 612 920 274 1269 1413 1655 611 728 25 351 851 1747 555 1364 1252 1633 302 1548 547 1380 1560 1741 118 434 403 1528 1148 1402 396 1295 624 910 425 915 869 1126 536 1725 1150 1539 212 641 34 414 154 1650 492 772 331 1615 297 1527 192 1161 727 1144 729 1019 191 778 251 1697 1070 1543 1442 1524 1381 1692 402 1471 1358 1643 1081 1273 67 1021 127 1123 857 944 931 1234 1283 1644 755 1725 219 1482 1007 1500 680 701 1178 1405 39 398 978 1609 921 1523 53 612 895 1315 234 315 525 1550 10 659 661 1437 1525 1741 89 284 1257 1268 893 1028 213 854 1287 1546 1090 1343 1162 1289 1003 1274 831 1738 909 1604 529 1398 702 1701 1335 1393 184 407 11 886 901 1484 589 1308 1325 1691 675 1053 22 246…
Output: 66

Constraints:

1 <= n <= 1849; 0 <= m <= 3698; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Separate Camps of the Ruby corridors - MEDIUM Coding Problem | CodeTikki