CT49989

Rhys and the Gilded tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Rhys found an old ledger of tunnels in the loft attic at the fox den of Rustwood. The margin notes pose a precise question. 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 <= 3217; 0 <= m <= 6434; 1 <= u,v <= n.

Example 1:

Input: 498 2346 128 335 97 401 186 407 94 359 159 301 154 494 43 55 65 301 425 483 133 241 98 320 101 209 140 356 28 498 60 491 162 457 130 456 177 442 222 312 163 451 270 322 71 153 170 389 139 441 465 496 95 288 259 323 95 169 370 377 148 378 15 148 43 436 2 205 114 244 305 311 179 190 168 353 376 441 16 257 181 272 468 489 83 364 169 244 189 493 136 207 403 446 117 403 100 166 280 287 3 275 157 438 256 403 93 350 46 369 389 441 41 121 303 392 117 453 25 68 189 282 132 374 83 406 77 290 66 420 105 399 153 493 22 482 189 406 216 406 68 322 268 303 216 225 107 282 33 284 348 424 330 435 181 397 488 498 184 262 238 345 334 495 184 447 4 354 94 457 70 296 135 173 5 94 13 193 222 463 177 476 30 188 351 426 47 92 194 450 263 359 211 400 234 253 205 257 78 219 267 481 21 228 414 485 253 264 174 443 43…
Output: 1

Example 2:

Input: 1401 3794 442 1227 634 1164 398 814 408 1319 62 183 252 1266 234 422 897 1169 861 1028 93 957 789 1167 563 1290 1180 1259 468 699 736 782 191 1222 284 659 229 1244 165 836 1024 1356 199 584 766 1380 984 1168 591 894 668 878 165 1129 403 1144 848 1336 102 1401 533 1034 344 1394 1045 1108 879 1246 1327 1339 320 681 205 827 84 925 182 500 855 1320 500 828 1 649 567 882 770 892 254 885 400 1051 842 980 52 398 250 950 1191 1202 70 1304 986 1382 302 1034 75 1010 531 1087 929 1246 937 1330 166 1280 466 811 914 1043 151 1127 430 780 52 675 112 1133 599 954 401 1138 705 741 38 954 292 1157 947 1377 1156 1304 272 582 960 1344 734 1109 344 1363 352 675 358 1312 176 284 842 1009 420 725 610 1174 763 828 373 1368 498 880 208 405 539 897 45 312 580 1160 110 1220 6 13 232 1106 1008 1296 65 203 152 1047 3…
Output: 6

Example 3:

Input: 1379 2509 67 451 105 1066 637 1082 534 811 888 1336 25 865 716 1342 107 939 316 554 75 1167 213 1055 693 792 962 1156 110 564 933 1151 191 691 201 978 874 1039 369 399 439 1282 132 564 1056 1222 688 1251 343 1362 791 1238 223 801 300 1250 405 1342 415 1287 299 1150 125 512 536 580 653 958 1121 1179 106 1315 851 1208 951 1016 164 1039 824 1197 1222 1233 260 466 975 1060 389 634 708 756 1115 1288 489 1216 230 1312 1049 1152 442 996 216 1378 245 711 91 186 708 715 35 602 949 1027 1038 1149 685 735 426 736 363 1228 335 686 463 958 1112 1305 10 1295 695 990 596 717 337 1193 578 998 404 970 444 726 1045 1048 167 175 435 764 173 364 224 1171 506 885 408 811 698 969 223 542 497 1265 837 1359 432 1185 864 1131 34 400 875 1149 909 1087 44 155 234 1196 257 771 948 1118 717 1079 183 957 978 1233 56 24…
Output: 38

Constraints:

1 <= n <= 3217; 0 <= m <= 6434; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Rhys and the Gilded tunnels - MEDIUM Coding Problem | CodeTikki