CT49697

The Separate Camps of the Pearl roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the pearl fisheries of Nacre Bay, someone must verify the safety inspections. This year the task falls to Owen, armed only with the roads register. 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 <= 1990; 0 <= m <= 3980; 1 <= u,v <= n.

Example 1:

Input: 796 290 635 689 414 685 507 515 1 677 194 419 161 176 73 115 612 795 284 645 359 639 152 372 278 559 580 592 58 109 139 399 157 332 476 565 323 407 482 566 96 290 524 604 303 588 49 565 59 551 187 196 600 776 86 375 403 669 274 337 354 777 320 369 622 625 30 218 310 774 446 720 106 171 539 599 24 420 66 592 154 752 285 675 283 395 278 709 457 656 219 637 454 589 317 600 61 337 446 635 436 656 487 684 329 544 668 780 388 689 314 324 39 209 586 655 33 735 307 502 583 613 246 587 295 343 702 767 58 282 318 558 214 649 603 755 143 651 35 681 198 640 63 200 484 753 41 334 169 614 62 477 55 339 189 624 392 656 60 172 670 729 597 724 470 781 406 496 37 190 499 505 383 390 8 316 30 303 286 693 68 295 92 475 316 562 47 444 433 722 711 753 253 418 587 674 739 791 434 451 438 589 237 242 306 746 78 7…
Output: 506

Example 2:

Input: 1693 2679 708 1377 170 1142 250 1181 370 1484 1195 1677 114 1339 546 665 839 1615 43 1052 438 679 331 425 932 1222 528 1655 109 1315 1521 1526 868 1373 292 636 164 1297 1220 1562 387 627 238 1079 380 1194 552 1427 194 630 1393 1432 556 1664 204 1341 679 1148 787 1028 470 870 84 996 1428 1535 30 782 766 1371 74 151 608 883 632 667 1097 1144 770 1329 965 1257 445 1023 305 786 730 1405 1480 1693 888 923 73 318 534 1655 247 657 311 1204 900 917 284 443 270 1033 246 1132 594 1165 1320 1437 202 1119 309 977 307 1002 869 1113 1458 1506 1467 1536 900 1368 266 1560 222 367 723 867 853 1076 259 548 784 1282 165 521 189 406 617 778 725 1668 1385 1657 137 1562 930 1002 392 701 1236 1692 147 262 376 1382 747 1407 429 1583 248 1507 630 1095 145 625 214 1567 41 423 225 254 925 1237 415 1650 282 1226 1232…
Output: 68

Example 3:

Input: 1036 1719 605 993 261 453 190 249 455 921 608 870 864 1000 200 539 93 159 213 354 207 799 883 1004 385 764 313 488 631 928 457 510 48 222 167 724 446 795 341 461 322 347 729 978 3 799 367 472 171 769 568 643 673 879 469 874 476 945 213 713 473 580 364 819 182 388 3 216 659 1031 164 437 104 639 495 653 118 449 138 330 395 950 726 735 624 709 42 149 285 505 869 932 87 705 443 822 446 509 10 456 301 688 835 899 711 1005 463 509 315 938 176 908 83 957 329 924 354 409 399 993 484 547 152 889 180 830 134 900 495 760 318 543 333 888 401 938 352 943 541 1016 515 532 2 425 39 638 760 981 21 638 298 829 561 682 256 986 604 766 517 596 407 757 874 962 152 617 158 290 23 827 521 593 415 782 49 547 192 309 518 801 758 838 28 791 517 671 3 183 218 766 97 803 580 789 409 851 736 763 521 848 352 486 214 6…
Output: 39

Constraints:

1 <= n <= 1990; 0 <= m <= 3980; 1 <= u,v <= n.

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