CT44029

Faye's Ledger of routes

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the observatory of Starfall; Faye weighs the day's routes 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 <= 2325; 0 <= m <= 4650; 1 <= u,v <= n.

Example 1:

Input: 1106 2415 711 835 98 786 617 699 281 823 41 199 835 985 425 550 112 567 29 329 275 583 164 366 439 446 43 121 581 822 788 891 317 964 42 384 445 493 556 730 78 342 150 514 182 191 376 778 895 1028 246 937 50 326 66 198 22 574 734 808 186 950 654 1062 202 962 182 747 977 993 213 1089 98 325 819 1085 34 389 762 987 61 887 262 525 308 621 225 796 76 753 324 477 55 407 907 926 640 656 984 1064 311 537 429 899 222 527 402 474 417 973 1007 1103 476 844 664 900 343 626 424 571 392 826 91 1085 447 1011 744 1074 558 759 317 415 204 495 508 972 684 956 539 599 660 664 192 446 124 298 515 898 482 932 3 483 399 518 306 498 579 922 694 926 754 777 192 729 39 443 96 350 45 910 431 568 414 537 100 565 923 1045 745 896 76 159 106 653 185 400 657 858 504 1010 893 960 217 591 867 1067 1019 1079 575 1071 417…
Output: 10

Example 2:

Input: 612 1794 247 528 106 491 46 577 260 569 28 250 152 609 167 539 243 555 430 602 26 420 52 346 106 502 375 430 184 463 391 461 15 606 100 319 61 79 403 571 560 594 391 554 549 595 76 519 224 373 91 245 305 375 219 229 337 425 342 527 246 406 161 329 12 451 470 577 220 338 156 241 292 378 96 177 7 137 262 359 250 432 397 480 277 522 82 214 192 584 184 230 410 607 222 408 82 401 48 403 47 454 298 376 464 542 253 266 319 442 285 466 398 416 318 416 252 364 244 314 154 423 158 525 283 363 32 276 346 570 42 177 256 469 351 485 588 592 89 414 14 551 178 464 152 532 227 566 51 411 311 342 518 540 414 555 439 606 76 130 4 561 283 396 376 506 361 593 295 568 233 412 61 297 44 466 141 419 139 562 442 470 51 380 43 152 7 228 185 478 138 323 186 559 110 304 49 77 200 335 117 300 515 561 16 326 86 475 40…
Output: 3

Example 3:

Input: 2086 2633 169 1004 110 848 486 572 673 930 410 1083 632 1880 1662 1691 804 1426 1440 1622 375 1767 966 2085 1606 1746 1723 1900 49 1748 1178 1395 19 1247 1042 1890 760 1886 684 942 1263 1714 320 349 1558 1763 1049 1154 967 1096 1789 1829 1256 1292 745 1951 1619 1863 348 1151 275 1285 766 1583 649 653 319 440 249 623 198 1879 557 1915 850 1636 194 790 364 1038 1002 1821 951 2075 71 1635 17 412 805 1811 455 945 426 932 187 939 729 830 95 788 194 1547 993 1084 1347 1910 882 1998 988 1719 817 838 663 1984 134 1103 1631 1682 376 1126 1177 1322 946 1675 1833 2061 1267 1984 832 1401 1100 1480 977 1994 315 359 408 588 560 1534 227 2045 268 609 357 1556 274 1302 309 1000 1342 1343 708 1539 518 1442 1446 1520 1783 2001 444 1613 1233 2054 835 1240 318 352 730 982 1316 1915 883 976 227 526 1185 1722 7…
Output: 183

Constraints:

1 <= n <= 2325; 0 <= m <= 4650; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Faye's Ledger of routes - MEDIUM Coding Problem | CodeTikki