CT30744

Tailor's Faded Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Tailor inherited the counting house at the mushroom groves of Fungaldeep along with its curious bookkeeping system for roads. Time to make sense of it. 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 <= 1586; 0 <= m <= 3172; 1 <= u,v <= n.

Example 1:

Input: 179 1507 104 174 100 109 37 134 109 143 86 108 73 130 35 99 7 63 36 139 15 93 84 104 137 168 14 175 19 130 115 131 64 132 58 137 48 68 3 138 127 152 114 137 122 145 73 78 52 84 30 161 74 77 33 76 38 154 42 148 31 153 23 76 140 142 1 173 100 153 8 171 27 68 33 159 16 40 18 28 95 107 22 81 148 179 31 47 91 119 88 132 81 149 21 144 11 58 22 115 151 175 51 81 73 127 108 139 1 155 152 173 114 129 83 162 85 120 122 176 148 151 125 155 15 71 8 129 57 147 24 101 62 69 21 107 77 138 71 78 40 151 5 112 12 143 84 144 95 118 130 164 29 160 52 86 116 152 4 90 67 122 12 60 44 99 80 105 31 121 35 140 45 54 30 143 61 72 161 178 14 104 112 171 97 165 15 67 37 153 81 109 39 159 151 167 78 147 8 122 8 153 42 155 33 43 59 109 32 97 18 50 141 176 14 25 72 107 80 125 100 118 106 118 51 128 46 54 5 32 146 168 88…
Output: 1

Example 2:

Input: 1437 749 1191 1329 88 230 945 1160 412 1295 806 1359 73 414 130 1307 536 1128 100 863 611 1155 737 1261 375 1428 836 940 548 1389 72 573 1295 1415 247 1241 128 637 84 934 150 225 21 1308 221 1123 304 694 313 591 213 1025 102 1038 458 1343 370 1089 409 969 325 1427 695 1171 132 1202 576 656 970 1002 100 1029 153 793 239 268 903 1185 1255 1299 98 531 1107 1229 478 618 1028 1314 293 633 653 1378 723 945 455 1319 705 707 12 1065 397 1408 451 932 476 562 1059 1339 133 1239 569 601 202 753 298 1265 802 838 527 728 609 1257 229 933 63 174 884 1273 738 741 647 1357 353 699 288 708 564 1323 439 1396 53 1144 1153 1427 16 118 860 1428 404 501 798 991 514 765 833 1341 2 752 147 231 62 810 15 625 568 1122 335 1131 807 909 556 705 395 704 86 1249 233 692 13 828 336 631 454 1211 29 825 889 1274 293 595 5…
Output: 688

Example 3:

Input: 109 292 16 104 24 37 14 42 12 35 16 76 17 31 43 45 1 82 13 75 70 105 61 87 51 96 58 67 18 67 11 87 51 100 8 40 12 60 13 83 79 109 59 99 22 33 16 27 17 74 52 78 68 74 43 104 40 103 19 96 7 75 7 38 13 105 66 101 26 51 105 106 102 108 9 98 77 93 43 60 38 43 29 99 79 84 3 64 17 54 52 103 31 60 67 83 33 88 57 68 105 109 55 100 16 57 2 83 7 10 41 45 1 16 43 54 60 69 63 70 38 68 66 95 44 102 7 79 21 74 10 20 2 79 42 55 1 37 41 85 54 84 13 65 29 67 92 108 66 106 13 52 30 83 34 59 25 106 17 56 20 96 81 98 23 93 68 109 47 78 22 43 50 60 26 99 10 88 29 75 6 86 68 95 60 67 40 101 90 98 29 63 28 71 33 44 21 40 9 33 23 66 46 47 87 96 10 65 71 85 89 100 7 16 11 50 88 90 36 64 4 33 28 90 81 96 9 58 43 65 18 85 54 65 27 41 52 98 13 44 14 93 67 76 14 22 30 58 5 79 56 57 94 101 69 94 58 60 48 55 91 109 39 80…
Output: 1

Constraints:

1 <= n <= 1586; 0 <= m <= 3172; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Tailor's Faded Ledger - MEDIUM Coding Problem | CodeTikki