CT54325

Iker's Bronze bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the maple sugarbush of Saprun opens only for a perfect tally of bridges. Iker means to find out. 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 <= 1278; 0 <= m <= 2556; 1 <= u,v <= n.

Example 1:

Input: 553 940 4 236 482 506 22 535 9 162 20 527 127 314 129 320 185 408 277 373 172 475 84 383 5 508 51 395 258 337 312 331 329 483 163 448 79 379 150 304 165 432 97 409 364 456 400 492 149 464 116 482 37 182 209 306 57 531 29 333 66 167 256 349 323 339 5 65 119 176 387 469 31 38 103 508 120 521 222 411 178 246 235 521 7 399 279 544 394 482 326 367 451 476 251 341 195 406 24 213 73 243 93 410 454 497 46 463 452 536 74 379 299 394 101 501 3 437 88 233 369 411 218 517 201 455 244 258 41 268 29 113 295 437 137 272 121 297 5 523 165 205 271 387 143 417 169 421 463 546 47 462 237 442 74 191 429 553 198 491 185 366 385 403 486 515 416 444 264 419 54 177 204 459 102 136 94 192 349 360 476 545 272 325 500 544 390 485 103 317 316 504 332 376 425 481 444 491 34 435 20 68 153 326 242 398 367 525 86 260 267…
Output: 21

Example 2:

Input: 957 1667 747 938 53 238 237 403 533 892 206 905 82 378 133 733 54 231 522 816 229 789 113 541 494 860 257 848 248 465 165 762 33 899 378 424 149 400 324 684 560 873 102 476 512 922 72 295 74 401 502 738 280 603 376 800 16 456 38 434 390 829 469 549 105 108 115 460 70 917 326 756 581 693 242 698 441 686 135 900 247 657 415 437 324 386 342 366 358 361 431 893 110 118 217 810 539 645 762 939 205 910 300 886 326 591 755 776 424 905 397 893 44 304 465 578 615 923 160 412 402 810 433 616 40 620 160 241 95 444 334 438 695 862 68 367 636 792 99 251 256 697 232 654 229 522 161 874 234 336 76 696 456 607 137 650 256 438 278 743 270 513 8 911 53 241 82 84 214 419 314 830 584 639 323 925 120 167 112 130 75 375 131 160 659 785 2 950 147 681 174 835 39 866 328 670 460 904 98 857 272 428 248 460 319 732 …
Output: 31

Example 3:

Input: 1055 2130 133 756 592 984 478 859 89 642 495 757 444 712 538 702 231 402 397 520 486 775 287 634 158 221 247 323 619 898 63 140 112 796 853 1054 347 550 449 561 312 776 281 604 117 168 365 377 335 599 318 702 67 239 20 960 17 74 705 1015 619 848 354 638 297 614 277 1044 560 947 76 610 166 493 37 990 228 265 193 959 76 446 291 378 209 305 207 791 548 700 256 763 79 993 233 371 229 676 19 757 5 772 46 403 192 353 419 482 16 224 225 270 5 674 167 735 316 757 871 934 349 564 281 362 115 934 223 1035 596 746 238 873 20 721 756 980 770 781 252 969 136 352 285 871 564 930 296 639 275 915 124 724 286 526 732 952 419 470 217 1033 462 615 552 886 319 756 673 961 560 844 127 509 128 861 108 295 376 639 872 921 267 619 494 986 670 1014 150 260 36 125 841 928 533 781 7 259 234 339 30 624 83 790 222 776…
Output: 15

Constraints:

1 <= n <= 1278; 0 <= m <= 2556; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Iker's Bronze bridges - MEDIUM Coding Problem | CodeTikki