CT52345

Chetan's Ledger of canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the cinnabar mines of Vermilion, Chetan records each canals in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1969; 0 <= m <= 3938; 1 <= u,v <= n.

Example 1:

Input: 1817 3076 661 1672 485 1199 200 1466 1399 1748 38 1136 737 1809 120 466 156 309 381 1115 801 1339 6 1728 489 1018 1035 1122 1755 1801 232 1161 730 1456 348 1256 210 294 288 1748 410 627 797 1272 493 1632 1116 1303 505 1100 400 1228 923 1542 564 845 1186 1353 1722 1783 894 1809 205 888 1196 1485 596 1468 822 1009 1359 1595 817 1205 23 1217 331 1137 1077 1523 71 580 1146 1158 72 1722 817 973 1192 1748 835 1604 444 1108 182 1811 1395 1695 45 1636 1198 1743 818 1737 1145 1173 686 752 745 1166 660 1748 798 1234 1249 1760 780 1124 958 1121 1383 1692 622 661 34 795 1497 1801 1004 1374 6 1721 843 1284 123 612 383 1492 1344 1393 746 1514 774 1169 561 788 65 304 299 393 262 951 1016 1696 638 1319 606 929 159 252 155 1274 901 1652 102 1099 870 1255 69 1007 152 1030 773 1705 64 1322 102 398 22 223 111…
Output: 68

Example 2:

Input: 714 2153 221 298 347 383 537 646 5 581 461 708 20 529 176 681 437 638 241 345 198 204 162 282 68 336 371 607 204 321 121 220 376 593 3 357 420 428 392 527 19 523 263 567 204 622 391 605 221 461 60 265 636 692 375 685 114 443 55 459 152 364 497 600 294 585 440 677 457 614 123 321 600 702 439 506 83 173 224 617 131 631 57 244 55 185 21 428 254 468 509 522 425 618 339 518 266 589 350 658 318 706 65 522 41 244 533 654 345 450 197 573 309 669 92 508 308 564 239 666 60 313 55 231 675 685 113 145 40 506 212 581 543 635 256 294 32 671 29 315 359 573 361 598 43 112 277 689 96 710 129 526 526 548 154 283 89 436 187 581 168 289 37 638 139 183 274 598 217 581 204 430 159 208 193 502 101 561 101 615 279 691 465 480 264 704 197 618 426 687 236 355 64 628 170 546 79 615 268 597 142 430 257 302 19 545 128…
Output: 5

Example 3:

Input: 932 2339 430 541 237 739 168 466 527 721 478 577 244 670 264 513 480 884 59 235 172 256 60 109 264 330 493 600 283 566 275 297 331 688 317 561 513 807 136 386 120 352 90 381 550 826 316 450 651 929 430 673 413 556 34 181 402 799 307 380 439 735 27 321 148 413 45 173 447 528 159 452 274 782 294 925 236 425 45 655 2 561 383 699 254 524 654 710 657 779 73 135 646 708 92 778 301 627 878 918 62 315 70 418 424 540 261 294 484 736 81 448 65 474 138 915 436 642 547 593 487 644 424 617 800 843 489 826 441 548 176 488 531 574 211 335 540 757 278 504 52 416 260 932 328 679 68 761 1 332 193 791 331 912 628 843 600 738 325 467 784 844 386 902 353 518 704 761 81 886 585 739 252 639 122 445 391 545 257 809 394 513 302 879 166 682 593 697 594 779 376 556 421 593 337 931 805 889 342 696 524 629 365 610 313…
Output: 6

Constraints:

1 <= n <= 1969; 0 <= m <= 3938; 1 <= u,v <= n.

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