CT43128

Bishop and the Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the savanna camp of Amberplain. Bishop spreads the corridors records across the table and picks up a sharp pencil. 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 <= 1844; 0 <= m <= 3688; 1 <= u,v <= n.

Example 1:

Input: 531 1061 174 391 43 67 320 509 151 224 58 508 53 372 39 183 133 377 98 514 66 287 425 522 137 163 125 416 133 267 212 506 110 515 313 459 314 511 155 205 213 254 126 399 250 260 166 287 314 429 128 516 312 444 206 449 125 185 234 261 89 431 211 214 31 466 206 471 17 217 250 441 98 270 171 442 27 321 100 255 487 519 368 518 161 358 182 280 309 516 4 404 151 267 22 383 244 437 330 415 138 456 380 468 430 523 109 277 94 322 41 403 497 530 229 385 429 510 58 183 356 502 443 482 122 520 345 376 154 478 48 403 5 158 108 419 346 528 299 314 54 262 289 504 436 506 180 371 26 319 269 483 105 109 167 448 3 477 314 398 262 335 46 422 170 439 45 207 266 504 128 170 459 494 144 480 320 406 142 411 9 158 25 365 87 280 110 217 166 290 78 524 479 502 205 350 136 493 48 288 398 484 30 374 124 423 107 177 3…
Output: 7

Example 2:

Input: 1481 1631 659 1425 450 624 916 961 309 1104 566 781 135 1416 64 867 295 1457 368 892 12 225 370 1315 1195 1308 385 909 1042 1265 426 978 217 938 838 1092 133 1457 18 1039 168 762 426 1087 1262 1327 629 1033 814 1315 473 1067 17 344 280 1362 292 1302 1085 1179 1294 1395 50 1253 224 336 872 1141 450 918 400 1217 816 958 531 884 80 1300 482 1471 884 1352 399 1266 803 994 844 1100 378 485 451 486 73 1417 646 685 369 1107 910 992 252 513 158 221 664 666 830 854 162 1217 1028 1169 237 1043 734 1156 519 904 829 1015 817 1204 896 956 934 1249 897 1420 1 662 1298 1318 351 553 614 950 94 742 440 1053 341 432 120 168 937 1330 472 587 94 1466 118 398 431 1203 553 763 968 1286 233 521 605 620 93 135 1230 1430 61 640 10 1328 438 695 150 1386 900 987 566 892 84 596 495 1009 476 1152 1033 1247 159 1437 30…
Output: 187

Example 3:

Input: 467 738 175 298 75 375 99 416 114 466 14 106 267 295 155 339 193 405 208 390 94 132 206 332 70 115 168 329 227 421 66 139 191 211 244 394 197 255 125 178 218 221 18 254 175 243 384 434 66 250 62 66 328 403 58 384 218 314 83 273 49 426 406 444 113 315 219 288 139 448 268 408 176 275 62 380 390 402 292 430 130 337 162 356 229 362 87 309 276 412 160 427 177 464 203 464 101 202 55 237 52 128 24 413 249 440 137 438 329 376 29 386 191 461 89 259 289 313 140 340 163 178 175 311 223 226 190 352 272 360 161 179 230 264 226 251 277 384 285 449 93 337 177 223 43 59 269 318 78 283 43 115 87 288 238 388 235 368 27 49 133 418 229 314 1 286 324 396 199 331 209 309 329 452 283 404 38 172 21 415 36 202 102 315 182 279 197 462 258 451 249 372 444 453 394 426 37 212 291 336 115 128 282 331 24 274 298 453 79 …
Output: 22

Constraints:

1 <= n <= 1844; 0 <= m <= 3688; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Bishop and the Separate Camps - MEDIUM Coding Problem | CodeTikki