CT37174

Last tunnels of Clerk

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Clerk inherited the boathouse at the wren hedges of Thimblewick along with its curious bookkeeping system for tunnels. Time to make sense of it. 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 <= 2578; 0 <= m <= 5156; 1 <= u,v <= n.

Example 1:

Input: 1444 901 174 1219 49 621 1081 1241 370 1130 100 427 701 1392 193 445 735 1118 835 1161 914 1198 376 1241 388 661 15 348 1032 1057 98 953 1327 1351 147 1296 85 1415 755 1203 576 1194 286 678 300 508 76 803 738 1360 815 1190 331 484 1035 1148 121 193 83 687 170 1283 676 1020 56 103 137 803 525 835 542 1273 1120 1402 594 644 130 1205 185 1363 686 1014 493 1141 375 1392 1019 1257 790 1039 349 1286 184 1370 188 1261 145 1310 650 666 35 1267 247 1169 149 465 380 921 133 998 953 1056 52 1073 587 1274 241 1018 140 1094 716 881 125 192 209 1220 142 1378 640 1251 395 452 1124 1411 1132 1140 600 1151 206 1137 52 422 53 664 40 779 648 1342 641 888 117 230 597 1441 782 1260 64 90 196 424 113 766 821 1358 265 1236 667 802 122 237 361 1308 933 1367 287 641 238 1053 281 1169 816 1154 44 441 763 1239 691 8…
Output: 550

Example 2:

Input: 1430 2936 1115 1143 1265 1308 1179 1336 571 831 671 1010 82 198 1040 1049 823 955 125 933 333 1005 1090 1365 495 1394 557 684 12 653 80 283 431 1251 550 668 1029 1186 8 1272 737 795 241 912 502 1213 812 1082 25 959 601 819 145 239 71 595 989 1236 523 616 83 505 30 1283 323 1006 8 1341 77 910 520 753 734 1081 422 493 644 1234 32 390 993 1082 472 509 415 489 865 1018 365 1365 732 1166 121 1184 193 820 196 360 547 944 195 1120 545 622 439 825 1158 1162 539 668 518 756 327 610 749 908 251 494 640 1139 146 933 1056 1194 333 973 687 1319 989 1039 780 1010 1073 1121 199 835 670 872 4 835 642 1118 249 612 94 1154 1007 1109 30 548 1039 1155 578 1056 302 1247 336 1412 552 718 713 1118 721 995 612 1327 53 662 367 450 598 1017 780 1242 993 1265 190 1323 270 1342 117 339 77 1032 190 1397 1006 1413 37 1…
Output: 27

Example 3:

Input: 692 3525 87 414 162 642 11 360 1 97 203 232 170 230 222 315 506 680 60 79 126 330 250 359 64 460 151 314 451 522 90 454 446 577 134 570 207 483 66 568 96 501 63 550 44 171 56 659 69 93 49 294 303 581 486 547 158 602 471 558 204 365 451 533 516 677 348 374 160 380 173 530 164 386 289 291 85 331 402 504 167 624 561 644 346 360 144 159 244 256 281 493 7 137 555 638 440 607 169 350 519 656 396 401 331 635 84 592 382 520 66 538 11 115 135 218 307 325 373 566 515 600 52 615 62 264 114 495 87 403 76 507 461 629 348 683 173 503 259 388 318 682 35 682 85 429 92 474 285 580 447 652 182 473 53 252 303 638 135 397 24 232 332 465 250 455 233 643 105 415 61 290 257 429 160 448 197 511 150 295 190 227 31 239 325 526 522 667 610 613 88 141 394 493 511 596 40 447 350 396 10 222 46 542 43 356 240 453 572 57…
Output: 1

Constraints:

1 <= n <= 2578; 0 <= m <= 5156; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Last tunnels of Clerk - MEDIUM Coding Problem | CodeTikki