CT32960

Baker's tunnels Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Deep in the frontier camp of Duskwood, Baker 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 <= 1686; 0 <= m <= 3372; 1 <= u,v <= n.

Example 1:

Input: 1125 386 181 438 714 836 285 712 927 958 284 604 733 867 532 1106 109 156 111 946 789 1016 379 789 22 873 220 681 168 899 493 928 484 583 813 1000 404 1005 132 276 575 730 190 753 52 496 344 786 101 700 104 1098 677 888 450 537 357 492 355 635 83 952 94 304 110 938 368 981 72 621 216 563 100 453 395 630 732 815 448 662 609 1112 597 1065 907 1121 659 674 60 555 232 400 46 922 839 1069 55 932 682 835 431 788 745 821 808 896 223 1063 67 1114 301 860 470 1125 221 640 73 1124 262 938 151 184 67 274 124 851 262 828 278 671 80 1116 48 96 602 1125 106 760 457 981 304 1011 185 1038 266 347 219 803 536 947 938 1065 37 470 724 946 257 822 44 134 600 743 567 1018 53 721 676 838 137 1078 9 276 90 831 602 870 520 684 354 468 266 1038 488 902 476 547 733 835 258 481 467 1125 615 932 3 1056 114 332 258 99…
Output: 739

Example 2:

Input: 509 698 88 486 135 366 257 462 21 346 214 264 56 373 14 399 8 374 294 413 157 443 36 126 31 211 276 501 342 444 64 391 99 397 48 282 369 463 23 191 110 428 165 215 114 391 118 325 452 456 280 466 265 436 11 413 273 352 88 108 130 197 174 215 322 412 59 189 219 475 15 438 300 348 230 503 114 505 349 351 207 315 204 443 45 381 49 470 4 377 375 472 206 224 100 420 315 400 174 416 397 435 79 267 42 155 361 404 189 245 75 493 219 342 123 350 117 240 90 257 32 341 269 329 48 157 424 426 103 347 225 409 149 296 108 412 67 426 99 343 181 459 85 91 282 366 267 336 229 230 81 239 113 410 121 177 186 254 375 400 177 272 113 508 192 322 1 189 173 414 44 167 111 438 119 145 237 343 219 280 69 159 181 305 463 480 234 272 158 208 225 352 44 388 87 413 157 382 67 116 325 465 80 302 73 360 44 468 243 408 9…
Output: 39

Example 3:

Input: 815 1185 228 782 374 723 163 337 111 384 316 432 455 563 64 755 311 587 378 755 442 502 21 468 202 620 172 507 45 462 30 278 358 741 325 366 617 713 231 566 295 766 152 265 112 650 519 806 186 694 548 771 32 450 281 769 511 772 515 661 28 737 496 650 188 618 651 688 106 616 206 691 56 468 246 641 202 349 650 705 525 660 207 284 214 490 402 694 522 668 100 587 419 450 310 579 409 627 320 577 392 471 60 617 380 787 726 779 217 575 688 720 103 199 139 163 21 683 223 580 79 621 566 801 157 541 541 698 45 58 183 440 435 565 41 704 237 441 260 569 372 517 120 237 206 437 537 694 39 718 327 451 410 518 253 430 196 592 273 551 222 261 481 700 137 412 88 186 271 306 26 213 486 720 309 579 159 391 6 615 372 518 50 622 13 391 208 234 533 655 238 410 453 471 148 464 12 606 518 789 476 487 138 334 375 …
Output: 36

Constraints:

1 <= n <= 1686; 0 <= m <= 3372; 1 <= u,v <= n.

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