CT45742

Fletcher and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the spice bazaar of Saffronia, Fletcher studies rows of tunnels entries. One clean number will settle the guild's oldest argument. 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 <= 1500; 0 <= m <= 3000; 1 <= u,v <= n.

Example 1:

Input: 464 421 294 451 97 130 128 257 173 205 280 428 166 249 65 177 250 292 98 189 57 192 179 337 161 186 111 288 23 94 304 339 194 331 191 204 12 177 181 198 291 333 153 296 73 149 125 463 55 325 396 450 258 453 194 413 93 360 17 352 36 59 162 198 184 430 138 240 2 183 72 450 160 393 80 411 165 440 150 387 37 415 88 408 62 111 56 370 73 345 293 463 306 384 273 348 214 239 75 164 290 385 21 372 121 383 169 276 139 402 16 191 74 326 36 328 109 177 340 352 21 204 17 356 105 370 122 142 31 448 221 443 128 449 185 449 142 353 37 441 154 371 118 323 224 445 149 440 198 369 289 459 192 365 255 395 61 417 68 383 323 361 101 185 100 285 30 253 87 323 192 269 40 335 94 413 201 363 97 318 84 389 369 413 28 164 326 383 25 122 130 169 329 369 40 424 7 62 83 161 91 199 141 462 229 248 329 350 9 283 39 418 85…
Output: 109

Example 2:

Input: 673 1868 21 558 197 453 614 673 279 396 200 264 49 438 76 274 142 531 76 457 558 622 50 294 173 188 97 342 153 184 419 499 131 470 30 279 216 408 411 509 176 249 157 412 27 447 195 256 351 387 26 591 148 234 45 577 275 451 646 650 329 654 262 486 179 210 128 532 22 114 100 668 458 599 110 529 38 450 246 394 294 548 333 557 68 629 327 345 145 286 82 484 181 359 195 616 186 574 47 58 126 269 164 508 333 542 262 466 439 648 186 435 380 409 151 595 20 576 156 331 498 541 58 362 228 635 5 663 104 602 178 605 352 614 223 315 169 541 14 544 15 498 267 580 67 516 99 374 46 109 121 397 122 385 636 652 344 560 627 639 69 291 35 633 398 523 613 616 205 291 67 93 41 561 158 193 319 448 202 433 147 278 470 567 111 522 203 269 29 178 347 383 55 347 44 169 48 541 92 403 652 658 535 608 128 283 247 322 43…
Output: 3

Example 3:

Input: 1357 1815 351 502 191 674 543 639 190 734 711 900 642 1094 607 1107 637 1330 90 1144 547 559 214 839 1058 1200 504 985 94 417 278 1347 264 601 192 1188 418 1102 728 1049 349 470 668 1347 155 1240 360 523 694 1198 95 824 127 498 240 957 940 990 351 1213 877 1304 372 647 70 1282 701 823 861 1242 435 1295 5 747 144 654 779 908 195 296 241 1320 248 1056 1033 1217 723 820 352 447 160 696 317 498 217 718 965 1150 489 1117 452 617 259 371 422 441 180 502 451 601 425 915 890 1154 40 618 61 1277 60 354 5 55 263 1054 955 1073 191 417 266 1202 756 1008 154 1133 492 1095 618 1212 770 1235 216 325 914 973 730 1256 448 961 247 886 279 750 485 934 376 1154 377 944 313 594 486 1196 154 236 451 1031 353 1092 114 571 148 318 936 1191 607 1129 300 853 63 1324 348 479 1 630 1205 1252 997 1285 94 908 916 1262 …
Output: 95

Constraints:

1 <= n <= 1500; 0 <= m <= 3000; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Fletcher and the Separate Camps - MEDIUM Coding Problem | CodeTikki