CT38061

Kian's Ledger of corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the ferry landing of Crosswater close for winter, Kian must finish the corridors ledger - one figure at a time. 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 <= 1906; 0 <= m <= 3812; 1 <= u,v <= n.

Example 1:

Input: 876 1496 651 790 173 545 277 306 451 457 639 856 456 734 242 323 378 806 307 659 561 829 167 378 161 335 634 807 100 476 51 485 322 380 134 444 118 291 342 674 106 509 404 607 478 560 211 267 161 235 87 239 380 749 74 527 671 736 211 865 68 435 128 266 122 791 320 755 25 740 416 501 38 741 147 256 223 427 192 861 117 227 776 803 566 867 391 691 227 587 514 570 461 663 615 647 99 801 540 550 62 692 745 782 801 822 456 798 583 845 328 819 334 627 705 766 281 457 41 541 54 747 38 569 122 306 473 574 622 851 756 789 67 598 466 728 654 712 76 467 510 555 113 560 439 695 388 622 87 426 91 654 187 495 509 631 284 564 169 842 227 405 83 751 395 550 116 353 48 73 108 468 248 407 397 606 434 864 6 7 122 355 119 247 397 673 493 638 39 268 6 769 46 772 213 225 221 579 493 833 377 480 275 533 688 750 2…
Output: 37

Example 2:

Input: 1458 2199 194 511 459 1423 223 800 828 1199 358 1028 223 752 31 857 633 1447 408 1424 13 267 577 978 516 958 511 1056 156 162 446 465 1134 1251 349 630 348 1455 405 794 554 1249 943 1421 534 918 1317 1426 283 1384 1026 1245 26 317 80 994 223 539 874 1389 563 599 245 500 147 1402 1192 1436 353 516 353 886 745 871 2 567 874 1019 720 763 818 1272 502 1210 373 744 115 1199 404 781 128 960 1036 1078 955 1113 609 1252 241 393 878 1273 994 1399 953 1293 791 996 795 945 947 1104 433 483 486 888 162 995 28 375 616 707 182 268 907 1107 17 901 647 1235 174 187 1351 1373 399 1362 273 1419 314 907 78 839 235 1122 209 1225 641 964 363 1113 545 844 777 1042 746 934 523 648 142 804 4 1380 132 502 338 895 245 928 1224 1259 828 1028 51 1094 95 561 235 839 422 731 467 795 530 606 635 1367 955 1170 1259 1305 …
Output: 75

Example 3:

Input: 752 2540 96 393 24 98 72 274 447 705 129 288 257 737 530 615 289 536 159 209 11 245 263 657 429 433 339 381 103 422 228 465 156 169 65 709 162 493 136 228 228 285 194 489 71 388 16 202 515 750 241 506 126 290 134 299 58 555 37 46 259 746 276 451 248 602 213 566 489 517 310 666 221 247 564 738 295 364 31 306 288 485 576 654 301 452 225 517 275 539 308 621 628 643 483 720 109 465 371 438 25 277 25 317 242 698 29 62 3 323 56 403 75 267 220 305 196 426 290 527 155 432 314 508 51 374 347 399 559 669 562 712 87 473 209 459 117 693 250 707 100 139 168 529 279 555 200 641 71 369 320 602 24 470 45 653 283 690 179 372 94 721 93 675 57 527 183 628 523 594 6 735 51 333 493 749 141 581 329 360 49 561 536 749 450 728 676 713 231 348 215 717 43 150 355 470 267 303 81 603 85 632 283 431 143 254 549 664 50…
Output: 2

Constraints:

1 <= n <= 1906; 0 <= m <= 3812; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Kian's Ledger of corridors - MEDIUM Coding Problem | CodeTikki