CT32724

Weaver's Separate Camps Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Weaver runs the greenhouse at the orchard lands of Applerun. Today the books show a list of corridors, and the numbers must be worked out before sundown. 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 <= 1017; 0 <= m <= 2034; 1 <= u,v <= n.

Example 1:

Input: 905 1701 727 843 146 530 562 789 92 735 233 746 442 904 187 616 493 755 18 133 395 773 477 882 206 386 631 821 81 489 112 260 377 874 460 750 542 657 306 898 17 255 185 273 339 692 402 646 118 663 421 422 323 844 37 676 13 883 204 242 401 737 27 293 311 567 154 492 407 768 418 623 68 363 516 773 109 215 569 573 525 720 152 269 448 845 129 816 272 413 161 479 420 807 124 578 425 623 74 455 405 665 365 877 102 365 365 386 95 242 628 673 417 472 377 770 335 424 298 864 254 371 427 812 106 862 125 494 513 589 38 501 218 508 253 702 85 435 379 845 190 479 451 547 423 619 63 401 475 623 182 800 93 393 813 832 30 857 451 877 264 466 170 200 335 425 133 457 4 386 326 643 667 694 213 602 481 873 12 63 57 630 45 167 601 788 195 488 224 371 457 631 190 833 335 709 461 561 374 845 176 724 312 661 600 …
Output: 23

Example 2:

Input: 122 977 17 46 17 62 7 65 84 117 91 104 21 80 33 103 53 69 23 26 63 116 29 100 26 45 68 72 54 108 2 44 16 73 94 104 5 19 14 95 44 76 65 118 52 122 41 104 13 57 68 74 17 23 3 85 29 38 34 74 21 108 5 103 47 109 18 90 82 84 62 80 30 106 32 53 18 69 102 116 34 39 23 62 62 103 62 70 27 69 24 113 4 33 30 108 77 114 11 108 48 112 1 70 41 91 37 104 19 59 26 101 52 93 4 44 8 54 23 63 116 120 45 76 73 85 36 41 13 51 5 74 28 87 86 120 11 13 94 98 26 97 30 105 8 21 95 98 65 120 3 9 93 110 61 94 35 122 39 101 52 81 63 66 8 75 31 68 42 59 6 115 13 83 17 121 32 65 2 9 14 34 79 94 102 105 48 63 25 94 28 111 44 61 81 99 12 27 28 109 29 76 15 120 14 28 59 102 70 92 60 106 34 90 3 41 1 13 52 69 63 109 78 100 96 101 99 100 83 100 75 88 32 74 63 87 1 33 6 104 24 41 6 49 5 84 69 120 6 113 17 115 42 76 75 122 12 …
Output: 1

Example 3:

Input: 582 473 196 266 76 184 37 222 179 405 375 532 261 265 93 515 394 575 507 575 115 579 66 147 336 558 6 374 293 472 397 415 3 422 50 520 393 448 66 180 444 470 488 580 76 235 98 407 401 451 410 443 158 407 518 519 336 564 171 479 15 271 463 529 31 412 307 388 347 431 32 96 370 406 160 560 34 241 139 444 433 552 180 548 491 562 60 245 53 572 43 265 178 358 191 429 131 490 209 427 64 462 98 375 448 455 58 454 89 96 142 260 282 350 266 497 115 410 322 371 136 299 305 386 173 228 182 232 244 489 173 349 408 528 263 426 15 411 501 504 343 474 216 486 56 145 220 511 20 501 372 386 410 519 205 516 190 414 172 419 26 71 59 230 59 121 39 562 373 503 165 450 275 324 7 121 184 405 267 418 73 159 283 517 170 575 25 352 157 389 386 513 16 96 135 392 88 237 282 539 289 422 43 367 227 277 114 550 353 537 6…
Output: 143

Constraints:

1 <= n <= 1017; 0 <= m <= 2034; 1 <= u,v <= n.

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