CT46230

Diya's bridges Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the lakeside town of Mirrormere with crates of bridges, and Diya the log keeper 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 <= 2027; 0 <= m <= 4054; 1 <= u,v <= n.

Example 1:

Input: 1724 490 520 1143 235 1302 91 1508 240 1543 1311 1434 484 1489 486 1302 205 1172 507 1674 530 1137 900 1456 212 1531 750 1319 263 863 206 480 421 1071 291 1607 114 584 877 992 300 672 182 293 247 850 374 1439 660 1604 426 438 562 1254 340 566 1189 1266 841 1554 1181 1433 898 1026 673 956 476 969 1280 1455 47 1515 378 468 1285 1709 272 536 2 83 1351 1503 1246 1663 498 1146 290 1183 356 894 14 149 51 1702 980 1182 35 502 1271 1653 578 1701 115 1426 523 1159 1034 1370 443 1016 924 1464 869 1010 516 1085 405 577 697 895 1200 1210 1169 1672 847 898 190 739 322 867 300 717 1189 1693 43 63 147 405 40 147 214 1575 437 1607 182 894 1364 1591 790 1071 386 1452 578 1705 848 1079 807 1220 749 1121 712 764 102 1337 1387 1516 660 1006 238 1194 1013 1434 386 462 497 1235 965 1277 1236 1287 675 1624 135 1…
Output: 1234

Example 2:

Input: 1906 2836 756 952 783 988 680 1353 940 944 359 1494 1542 1659 197 936 22 925 546 593 723 1119 1068 1825 748 1292 12 1072 17 717 548 1294 922 1522 211 1158 360 1471 189 1076 390 1573 1442 1643 1193 1275 722 1692 1011 1291 1007 1824 770 1205 1260 1653 1090 1782 1335 1624 803 1162 750 1214 802 877 510 1533 239 1798 1797 1871 716 1149 1237 1688 182 396 791 1425 1515 1578 47 1787 355 917 497 945 17 823 759 1555 372 1199 489 1832 166 681 1397 1613 16 809 535 1573 1352 1683 223 1367 84 382 876 957 153 718 1223 1407 619 1356 1457 1688 149 386 515 679 337 637 510 1555 1635 1886 655 1882 1748 1813 1308 1583 15 1513 75 718 326 827 1310 1481 884 1506 1447 1579 982 1295 540 1728 208 1297 706 931 348 1763 754 959 282 571 243 1858 1658 1739 282 349 188 272 792 1583 560 1667 461 1801 494 1181 1323 1455 14…
Output: 98

Example 3:

Input: 1504 3944 568 923 588 1483 897 1403 72 1144 302 629 746 950 427 1029 312 985 1076 1459 185 798 741 1356 359 1473 94 487 569 1033 116 1451 14 135 517 704 177 1188 443 809 661 729 190 386 624 906 818 880 996 1089 565 1116 228 298 410 1446 239 714 1453 1470 142 985 1214 1263 285 1299 610 1104 714 1166 54 1318 299 1141 1145 1330 46 707 551 1131 456 554 898 1015 336 775 412 501 463 1374 249 1415 899 1439 302 873 1142 1322 745 1292 332 872 494 1316 274 293 989 1137 223 1035 38 634 208 668 581 1055 769 1153 521 860 356 1222 219 265 178 583 353 456 314 1064 455 1295 111 169 859 1027 402 865 330 1048 174 1455 277 864 832 1391 99 1293 351 430 215 335 382 1392 460 803 1046 1163 427 517 17 847 328 733 409 1019 69 611 70 1211 155 1466 321 705 47 1477 658 780 268 669 980 1285 383 1051 27 347 286 1157 49…
Output: 8

Constraints:

1 <= n <= 2027; 0 <= m <= 4054; 1 <= u,v <= n.

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