CT42339

Verdant corridors Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the foggy moor of Greyfen with crates of corridors, and Weaver the cartographer must account for every last one. 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 <= 1517; 0 <= m <= 3034; 1 <= u,v <= n.

Example 1:

Input: 641 596 238 318 174 254 629 632 64 169 324 554 205 224 421 468 38 442 207 410 256 359 146 344 115 594 264 335 1 27 298 530 10 532 129 342 353 406 78 432 138 371 303 365 19 512 341 462 145 234 233 325 333 595 279 315 69 429 126 363 222 444 7 337 112 622 207 527 265 419 51 427 4 228 153 392 329 628 42 288 16 317 21 403 180 615 383 404 579 622 297 548 322 358 116 538 220 324 166 558 330 499 425 553 180 482 148 568 425 633 119 131 516 545 296 434 89 579 259 405 77 494 37 464 336 399 86 151 47 323 434 483 318 541 211 230 116 589 267 315 180 326 459 551 67 232 118 476 48 287 157 452 155 408 161 209 10 23 116 293 216 332 556 597 462 478 538 574 89 141 389 409 420 470 287 544 32 138 103 113 146 351 478 482 397 620 103 520 9 170 373 444 298 319 318 600 227 448 118 536 92 546 314 601 181 396 77 315 …
Output: 110

Example 2:

Input: 288 2590 175 206 38 46 3 212 130 229 32 143 178 260 72 143 108 242 132 269 18 40 92 100 172 242 224 242 201 280 85 193 246 256 68 101 38 270 28 237 25 178 51 207 145 270 112 257 211 278 8 86 8 210 31 113 4 204 210 244 74 212 152 271 5 161 11 48 51 204 12 250 228 249 15 132 87 288 136 209 7 24 48 240 142 271 253 255 199 287 198 214 59 87 38 42 54 234 13 164 117 275 107 272 220 272 146 212 143 184 12 40 63 89 100 146 154 224 139 175 64 118 8 102 34 255 205 275 97 255 10 111 139 205 5 284 17 115 27 117 32 49 228 272 181 284 106 181 219 259 27 215 164 254 214 272 22 129 164 263 17 79 133 286 146 218 65 116 78 94 41 129 19 143 148 195 34 60 59 109 132 218 92 270 33 223 28 175 29 81 131 205 33 214 137 263 20 156 63 120 13 202 204 218 86 187 2 44 5 221 175 283 42 211 113 286 131 202 105 132 79 16…
Output: 1

Example 3:

Input: 1353 645 149 1308 319 1154 590 951 134 1130 1029 1114 999 1284 722 1055 787 1063 409 554 170 587 209 1128 512 947 100 559 581 725 676 924 532 1352 902 1140 98 1258 269 1161 261 1293 499 860 475 774 536 1147 218 693 77 158 361 738 490 1275 53 150 728 849 593 1078 422 1294 284 1173 548 593 136 1144 877 996 1149 1333 202 923 328 1055 835 1160 489 1043 99 1329 86 625 195 1009 374 625 97 1104 457 674 650 1187 127 629 211 1161 1149 1291 350 790 52 245 672 777 271 864 509 1181 876 1043 418 1313 513 917 560 996 711 1187 722 1339 896 1323 54 1116 845 1211 6 419 454 695 47 312 164 1017 243 309 756 1004 445 525 175 972 845 1292 38 469 181 830 1021 1189 914 1185 161 323 124 1208 794 923 558 728 1270 1338 454 1204 1167 1336 834 948 218 394 812 1093 903 1240 976 1049 501 595 373 378 155 603 364 681 1051…
Output: 709

Constraints:

1 <= n <= 1517; 0 <= m <= 3034; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Verdant corridors Separate Camps - MEDIUM Coding Problem | CodeTikki