CT32248

Boris's Jade Ledger

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Deep in the caldera rim of Firewatch, Boris studies rows of bridges 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 <= 1898; 0 <= m <= 3796; 1 <= u,v <= n.

Example 1:

Input: 1388 916 1149 1301 134 1082 203 793 547 643 728 1108 388 799 868 994 1112 1230 32 1108 178 503 57 765 151 553 1002 1199 443 950 403 514 1063 1250 49 608 162 1095 22 163 223 373 5 828 722 1039 73 562 162 1078 778 1027 166 250 407 408 667 1133 87 845 145 1021 436 1180 554 1267 35 1248 144 175 509 778 151 203 209 583 417 1079 301 331 177 1297 532 1172 626 898 1359 1370 75 395 625 684 317 1015 150 1170 71 731 786 1104 125 1022 413 680 730 1178 489 1005 12 782 64 1300 600 708 329 810 742 1209 257 1189 1310 1337 888 993 6 897 115 474 329 620 456 562 472 1111 42 1197 777 945 436 1077 981 1316 72 1111 597 1071 193 1194 1077 1289 507 1178 390 1274 496 543 369 651 747 1316 640 805 935 1278 564 1062 34 440 697 1220 16 1055 73 774 599 1128 365 757 450 1072 403 1024 374 904 853 1200 835 1015 37 663 563…
Output: 503

Example 2:

Input: 1464 3559 665 823 863 1184 238 1040 100 520 1015 1257 105 836 930 1283 1163 1262 640 1310 104 562 872 1297 155 1380 132 786 843 845 93 909 82 771 168 773 178 1316 148 183 160 387 446 1083 168 1436 722 1092 274 417 879 1043 203 1334 182 1075 484 1026 164 646 956 1400 490 785 61 871 390 421 366 1331 696 1010 259 972 173 1074 145 1439 201 866 750 847 152 225 175 1412 646 1445 730 1437 918 944 4 1163 1146 1304 327 674 412 806 143 1329 61 605 65 799 707 1115 991 1116 125 982 161 881 133 1431 1 1004 1298 1448 923 958 877 1058 265 695 126 351 1104 1337 347 579 615 984 299 894 174 235 499 800 1217 1356 450 1080 436 1291 636 866 147 1463 864 1254 344 1311 639 1238 1123 1199 457 835 718 1090 15 1362 919 974 894 1317 358 421 887 1204 672 1322 1110 1322 704 1112 840 910 189 1164 827 1077 494 1014 1223…
Output: 11

Example 3:

Input: 832 1572 397 808 137 696 425 557 48 228 316 598 342 590 560 608 270 363 370 685 132 626 528 733 99 754 451 712 445 832 136 631 52 683 567 802 422 672 561 669 126 561 420 634 33 745 74 829 199 685 353 672 164 764 591 737 253 567 263 552 153 510 528 749 547 616 299 796 30 249 180 348 478 530 81 85 173 631 28 790 549 634 101 254 469 705 153 154 281 388 634 768 680 797 45 606 38 786 507 660 384 502 540 766 349 448 538 660 331 768 237 242 187 491 702 750 259 493 57 816 420 450 81 553 690 804 656 752 384 765 584 786 338 631 182 567 649 699 181 438 483 691 90 721 210 448 145 716 126 259 266 572 105 719 316 537 384 727 372 376 304 525 188 317 674 692 210 550 300 329 511 736 163 578 385 805 467 626 531 759 243 828 315 745 485 508 535 793 390 664 219 592 371 761 24 511 366 577 475 630 651 712 640 80…
Output: 21

Constraints:

1 <= n <= 1898; 0 <= m <= 3796; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Boris's Jade Ledger - MEDIUM Coding Problem | CodeTikki