CT33140

Wheelwright's Ledger of tunnels

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the shipyard of Keelwind, Wheelwright records each tunnels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1213; 0 <= m <= 2426; 1 <= u,v <= n.

Example 1:

Input: 338 689 58 79 132 163 53 203 33 320 26 197 15 129 133 199 77 223 22 171 69 100 39 175 254 317 93 313 54 225 217 241 90 289 47 250 108 266 139 337 48 250 88 257 32 313 183 324 143 250 124 188 27 45 105 225 21 245 76 177 215 318 12 234 34 298 65 223 10 131 2 75 26 235 144 209 132 175 99 324 75 245 62 105 116 197 132 135 85 218 161 233 219 332 258 314 20 123 175 255 11 230 251 313 191 313 135 310 4 238 220 331 114 289 41 296 184 237 69 123 60 325 174 186 20 178 222 283 28 55 140 161 241 276 25 280 221 331 28 88 112 287 13 307 265 324 68 231 187 208 85 193 164 184 14 95 42 265 117 288 32 69 110 182 240 321 171 281 116 311 172 327 128 154 219 279 218 279 59 62 155 323 25 213 8 324 64 273 22 48 261 333 62 286 99 223 69 99 125 220 119 135 63 89 60 144 110 114 2 83 101 156 33 177 203 265 8 48 273 …
Output: 6

Example 2:

Input: 1196 807 182 956 524 845 46 645 301 919 876 893 652 828 726 1189 297 467 334 643 476 1084 944 1122 248 1025 423 593 724 914 888 1015 90 351 928 1052 171 796 198 573 87 98 162 934 124 398 437 668 1152 1192 585 1087 158 923 561 862 81 102 784 1165 34 413 316 367 155 309 509 991 174 1139 353 640 549 682 533 946 126 812 197 492 361 895 145 433 386 754 70 651 44 122 249 600 626 683 307 655 250 515 295 533 316 1044 722 1054 351 1066 198 522 319 868 640 1070 690 1042 755 804 87 584 1006 1077 95 1144 517 1083 173 884 204 741 435 732 361 366 694 965 394 595 927 1108 572 1162 459 757 237 1134 24 212 199 806 535 913 627 760 230 640 341 551 388 980 10 845 709 1126 496 828 208 231 637 1182 778 1151 15 158 386 799 554 728 430 543 188 1160 100 612 317 731 70 232 656 892 172 259 579 798 266 682 558 893 32…
Output: 405

Example 3:

Input: 11 2 7 9 3 11
Output: 9

Constraints:

1 <= n <= 1213; 0 <= m <= 2426; 1 <= u,v <= n.

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