CT30788

Nandini's corridors Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Morning light hits the canyon post of Redrock as Nandini unrolls the day's manifest of corridors. The tally will decide the next shipment. 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 <= 1924; 0 <= m <= 3848; 1 <= u,v <= n.

Example 1:

Input: 1473 3277 104 698 1068 1203 517 1136 48 128 1006 1295 419 604 120 360 234 519 302 1449 389 1472 50 573 499 1332 252 1288 1182 1306 249 1209 1000 1257 429 843 431 834 333 768 849 1465 231 1156 233 497 610 995 478 582 126 534 607 939 832 1357 369 402 870 1295 778 1266 822 1469 325 717 464 719 16 70 78 1213 613 1143 88 1174 299 1003 311 1313 140 253 114 1195 64 958 175 1350 1152 1416 850 1006 1087 1294 90 1411 539 937 879 977 189 605 608 1183 33 1346 746 943 211 1110 304 1137 301 1466 245 1240 902 903 694 921 660 1281 1031 1055 367 830 262 1105 231 904 1078 1343 712 1332 351 433 240 1467 524 626 835 910 761 909 324 1345 400 738 628 1276 184 1214 676 1144 46 395 131 1279 298 537 475 1085 585 787 831 1315 174 839 1078 1133 844 1231 281 1276 621 1013 252 552 389 1448 844 1363 22 1351 65 282 637 …
Output: 18

Example 2:

Input: 273 2855 132 252 1 229 122 267 87 105 34 81 241 268 88 230 67 159 41 154 23 170 165 228 58 76 84 148 16 249 182 220 116 234 165 227 44 99 247 273 1 45 57 73 129 147 46 167 82 223 124 163 72 142 63 183 62 199 168 237 101 202 197 248 98 231 84 115 136 229 218 220 111 207 94 210 103 119 120 121 8 252 12 59 31 37 45 87 181 191 81 96 62 105 147 152 60 67 12 133 129 212 212 216 76 174 61 140 145 194 172 229 102 157 2 74 51 85 50 188 113 244 47 169 137 267 14 32 106 249 49 56 147 253 140 142 144 245 77 269 120 253 159 208 31 180 15 56 55 227 153 163 109 169 78 97 117 183 77 215 76 257 212 260 271 273 38 268 244 249 103 264 14 71 114 185 57 82 240 270 3 168 158 161 22 269 1 271 140 219 60 165 94 184 163 269 111 230 28 137 76 152 28 168 124 178 92 177 38 193 81 198 148 180 36 251 34 240 97 232 123 …
Output: 1

Example 3:

Input: 1403 3363 798 1010 916 1049 527 1271 688 764 252 409 193 308 364 725 688 1181 169 231 95 101 433 947 688 1067 400 649 1348 1364 537 953 733 912 543 835 595 600 238 1396 1161 1254 479 1079 124 612 824 1203 587 1344 795 1378 258 640 1010 1330 355 647 272 587 1165 1320 231 1288 41 1347 128 146 182 605 252 1337 210 778 405 759 962 1255 113 1381 339 966 647 1151 454 1263 560 1235 328 440 1105 1347 625 1039 937 1348 241 513 209 1394 582 907 643 963 155 346 593 1247 115 564 298 1395 260 540 565 1027 767 1360 1145 1376 101 1044 1266 1293 596 908 172 1249 246 1073 441 911 79 174 281 400 825 1269 544 680 709 965 396 1192 291 869 120 778 275 361 116 498 249 886 123 411 34 877 47 543 193 367 472 1102 294 576 728 1052 394 974 795 933 203 310 317 1230 157 932 376 620 833 1203 160 553 160 885 922 1114 53…
Output: 10

Constraints:

1 <= n <= 1924; 0 <= m <= 3848; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Nandini's corridors Separate Camps - MEDIUM Coding Problem | CodeTikki