CT47449

Alaric's Tempest corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the lotus ponds of Tranquil Basin with crates of corridors, and Alaric the clerk must account for every last one. 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 <= 1744; 0 <= m <= 3488; 1 <= u,v <= n.

Example 1:

Input: 1598 1805 338 1015 92 1478 64 1227 1209 1266 3 997 800 1117 542 825 714 781 1123 1333 1044 1152 1014 1154 630 654 809 1574 1021 1127 1134 1400 1464 1590 714 1149 622 1149 167 901 1440 1521 1176 1501 705 1209 95 1416 761 1333 592 1009 523 598 26 1096 242 518 1026 1394 789 1109 851 1515 84 364 462 1278 12 1515 1458 1499 358 1287 182 255 105 499 712 1370 5 1417 239 769 849 1282 1002 1046 436 1480 79 545 902 1169 338 447 180 635 1193 1508 1304 1571 44 1299 341 789 99 1226 519 605 89 740 152 1487 746 846 22 667 184 515 1235 1532 756 1518 740 1157 305 1345 64 329 827 1212 313 421 143 824 224 689 638 1526 218 591 773 801 1547 1578 465 672 628 1266 1178 1205 26 843 361 1383 59 1064 669 978 346 851 41 625 39 405 1555 1576 282 1299 150 1084 418 1362 929 1304 736 895 69 809 951 1304 1058 1512 379 135…
Output: 206

Example 2:

Input: 1115 281 901 1068 209 588 231 594 18 1035 241 401 330 1036 902 1052 222 961 247 418 656 888 397 739 87 96 695 900 469 720 1039 1065 502 532 240 302 463 1102 467 897 304 685 554 926 312 922 267 1095 91 1034 622 1028 503 1042 165 672 507 1090 281 353 460 899 47 1091 630 648 318 412 357 621 83 921 693 825 890 1040 80 143 627 773 547 797 448 924 435 958 113 491 698 713 909 945 294 993 744 826 719 867 494 686 651 1114 545 758 448 1070 515 637 46 148 955 967 226 486 148 1027 271 746 504 599 154 505 118 442 20 367 557 1070 302 452 137 1009 207 800 120 898 180 369 436 700 490 526 653 1092 601 611 581 964 793 982 528 1037 197 791 604 737 584 732 974 1052 861 1106 465 944 347 370 932 1001 638 1011 200 271 480 836 460 589 613 666 38 818 340 739 153 1095 220 674 183 1099 782 1113 104 640 253 759 35 10…
Output: 834

Example 3:

Input: 1672 2447 630 676 466 1419 568 628 368 1419 850 897 502 682 1159 1640 401 639 568 1592 728 931 1114 1346 725 939 126 1442 365 622 186 992 933 1467 52 1556 791 1523 1502 1519 471 1143 1187 1434 1171 1649 402 853 893 1633 325 1346 366 971 509 1643 622 861 484 1598 139 229 456 1178 329 700 580 1515 275 1088 1347 1370 287 1079 598 1172 583 1578 1074 1556 511 1048 427 1109 464 546 301 867 813 1515 375 1463 494 1182 238 744 202 815 455 1527 554 1596 73 871 316 832 894 902 402 1130 246 1128 1026 1465 351 1341 271 1357 325 780 933 976 34 271 8 1284 522 823 1613 1630 577 1119 139 478 4 267 60 566 1237 1483 282 481 883 1388 317 435 874 1043 88 438 1433 1471 427 1446 189 674 307 1445 257 539 870 1475 225 1586 1315 1342 388 1613 5 431 5 909 686 1457 68 151 1040 1562 87 1120 795 1428 1157 1544 644 1136…
Output: 99

Constraints:

1 <= n <= 1744; 0 <= m <= 3488; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Alaric's Tempest corridors - MEDIUM Coding Problem | CodeTikki