CT47717

Indu's roads Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Indu the cartographer watches over the copper works of Verdigris's stores of roads. A careful computation stands between order and chaos. 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 <= 2876; 0 <= m <= 5752; 1 <= u,v <= n.

Example 1:

Input: 2695 3963 859 2245 983 1107 946 1945 920 2540 2239 2373 1634 1814 1273 1389 782 875 256 2523 493 887 1174 1857 970 1127 443 453 254 2622 758 2394 1913 2344 2575 2596 739 2665 1690 2502 134 870 1246 1809 970 1767 1366 1846 2347 2395 407 2652 87 2521 430 2420 95 1419 1404 2692 7 627 1903 2210 1846 1887 1555 1806 1147 1954 1930 2164 1398 1510 204 1775 646 2511 75 838 1515 2568 1114 1504 74 916 1180 2039 442 2405 74 317 985 1544 1147 2069 433 2221 441 2566 154 1955 1811 2073 326 1362 1396 2227 763 2059 66 862 366 879 1497 2339 40 725 1896 2666 476 822 1659 2150 288 838 162 1848 518 2303 242 255 1413 1649 712 2079 1470 2070 895 2214 187 2294 1261 1871 934 2441 1301 2045 528 615 647 1785 1016 1139 161 499 238 1955 1593 1671 1259 2227 848 1342 823 1708 1122 1259 1048 1901 386 1158 1848 2269 265 1…
Output: 145

Example 2:

Input: 1419 2355 324 1196 514 742 725 1348 588 791 496 720 701 746 88 390 735 1107 882 1164 61 228 735 1024 79 424 388 743 293 361 31 1064 138 259 322 1335 81 462 400 717 407 847 204 586 75 469 125 1399 518 905 201 962 613 1064 97 546 216 967 83 432 412 774 395 1226 974 1191 178 486 38 1057 870 1220 73 151 898 1255 717 980 158 811 491 960 442 517 626 648 40 673 277 659 156 388 75 1340 219 618 300 505 730 1300 584 634 539 678 93 1158 67 175 862 1200 657 748 245 842 110 1371 754 917 730 1021 553 833 559 1338 891 975 375 1194 624 793 1151 1381 346 479 473 1223 35 560 189 1007 619 862 691 773 1180 1367 46 843 420 585 994 1353 40 851 549 1067 275 380 531 958 975 1143 458 1281 1146 1282 176 1003 1113 1413 1122 1372 160 856 391 869 1072 1210 780 823 400 854 94 139 391 427 268 1312 19 377 501 676 280 553…
Output: 49

Example 3:

Input: 820 3600 232 476 82 363 683 694 312 340 328 443 302 778 191 473 499 620 84 317 96 333 470 571 84 607 188 612 156 190 497 767 217 268 95 206 562 588 139 427 82 765 124 785 437 610 512 673 301 518 254 380 304 694 427 788 186 724 365 734 128 784 118 369 152 303 38 808 456 539 357 369 218 582 285 306 319 708 351 724 563 606 630 715 13 204 226 524 327 518 271 564 16 771 157 747 190 529 98 729 407 494 332 790 37 465 352 609 41 718 43 677 45 274 366 679 74 149 2 7 243 273 102 372 379 476 168 775 182 350 325 347 164 173 106 343 707 802 272 514 449 456 126 747 350 810 648 779 247 557 306 482 107 446 348 548 165 291 483 679 308 441 271 657 169 657 343 355 613 686 140 668 516 819 68 390 6 349 436 613 20 446 241 758 324 783 42 746 96 129 207 639 767 793 673 723 266 580 168 513 96 425 389 539 556 803 2…
Output: 1

Constraints:

1 <= n <= 2876; 0 <= m <= 5752; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Indu's roads Reckoning - MEDIUM Coding Problem | CodeTikki