CT40032

Theo's Northern corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the foggy moor of Greyfen, Theo studies rows of corridors 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 <= 1235; 0 <= m <= 2470; 1 <= u,v <= n.

Example 1:

Input: 807 2156 164 652 166 787 17 540 10 548 262 510 491 617 165 639 58 786 222 379 269 616 90 438 55 416 611 674 397 638 179 448 140 199 50 380 285 460 609 781 610 695 231 468 704 767 332 683 572 740 83 141 57 793 10 431 276 644 528 760 67 305 187 443 93 778 498 788 291 631 343 480 32 774 120 727 64 775 198 638 75 309 148 342 330 531 420 761 448 473 198 202 516 658 510 684 165 704 623 627 69 503 397 789 495 742 482 645 34 748 360 628 769 797 111 781 145 684 210 685 57 622 560 579 322 728 681 714 78 583 168 589 52 806 194 477 160 609 143 187 359 759 202 737 267 368 386 671 156 588 67 289 50 782 155 761 108 684 61 225 227 262 525 796 610 720 296 775 47 677 179 549 634 796 4 662 259 654 435 511 173 369 531 540 327 434 443 674 110 274 12 48 363 798 650 776 167 732 223 700 312 372 51 647 29 781 497 …
Output: 3

Example 2:

Input: 839 1936 275 754 124 220 110 714 65 469 306 610 506 825 12 682 341 657 44 481 150 825 103 646 713 785 173 416 720 823 2 636 133 705 64 165 30 451 391 618 578 817 97 273 13 754 401 413 58 183 47 110 666 797 487 802 78 439 236 730 84 414 220 615 249 446 148 767 626 765 105 555 28 643 253 320 420 736 7 256 231 233 156 357 420 466 73 325 268 614 101 590 187 373 377 541 460 524 590 776 459 837 239 488 206 501 508 608 649 786 344 739 549 657 244 626 103 776 55 222 499 763 43 333 24 714 100 247 202 484 192 254 118 280 337 478 783 798 225 555 190 416 196 645 145 505 150 238 88 268 12 759 68 391 498 773 149 538 338 568 103 298 316 784 57 643 564 647 745 748 241 731 229 255 407 797 483 534 145 787 433 722 226 743 237 455 78 366 577 830 135 331 632 700 532 650 271 623 155 235 452 568 362 532 59 77 17…
Output: 8

Example 3:

Input: 362 569 77 328 15 111 44 97 102 252 16 287 33 175 129 270 217 235 80 177 169 176 12 51 3 305 18 322 58 198 25 358 103 293 97 198 114 241 86 220 29 305 84 314 131 343 177 241 135 141 73 122 185 334 145 218 172 241 240 292 90 115 44 315 10 331 183 317 5 122 150 298 25 51 24 199 187 284 44 250 166 209 161 292 164 307 279 329 3 310 47 359 129 360 48 272 119 157 101 103 4 102 90 343 228 262 79 200 84 362 154 324 268 328 85 88 22 329 125 310 131 185 181 212 207 266 36 57 177 222 19 98 10 318 153 283 30 153 37 301 113 250 182 292 160 359 83 311 80 97 245 337 273 344 117 323 49 258 223 309 136 180 38 180 88 310 12 344 105 235 329 346 132 319 69 96 37 112 127 250 295 336 185 323 274 283 21 133 3 75 46 304 18 290 123 304 105 228 130 143 241 253 198 317 92 190 175 261 120 156 30 54 106 317 109 221 16…
Output: 17

Constraints:

1 <= n <= 1235; 0 <= m <= 2470; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Theo's Northern corridors - MEDIUM Coding Problem | CodeTikki