CT37936

The Separate Camps of the Teal roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Tanya found an old ledger of roads in the greenhouse attic at the acacia flats of Thornveld. 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 <= 1583; 0 <= m <= 3166; 1 <= u,v <= n.

Example 1:

Input: 1047 522 627 874 62 483 85 99 211 273 422 836 116 355 160 542 144 379 243 589 146 472 70 288 385 1013 481 562 256 829 867 935 867 914 146 1008 995 1044 92 1004 47 224 688 1006 537 595 10 95 534 673 46 102 220 744 217 421 562 958 240 453 819 868 466 1023 290 429 836 1039 270 984 514 870 543 1034 709 723 546 585 536 822 564 839 29 678 359 901 350 537 459 634 158 963 858 872 197 375 422 688 869 890 47 455 401 1037 946 979 88 553 262 917 360 874 190 263 59 852 453 663 278 524 299 733 357 960 764 981 386 845 129 991 431 690 563 1041 9 449 171 656 7 599 199 247 535 646 683 908 74 424 180 571 456 806 668 759 266 851 274 814 771 792 290 876 259 946 528 566 237 707 461 588 224 990 225 289 533 548 128 130 555 814 991 1022 325 770 2 670 89 214 146 981 277 666 779 890 100 899 517 1039 159 860 56 394 8…
Output: 526

Example 2:

Input: 510 422 320 500 367 473 185 457 163 233 325 399 89 391 201 387 453 490 56 233 286 445 57 85 307 333 357 474 57 351 22 305 35 343 360 390 318 468 344 423 73 488 201 269 166 470 367 420 263 509 165 425 492 493 110 498 18 176 69 190 19 342 110 387 294 300 29 273 97 338 271 404 289 295 305 365 254 465 14 251 155 210 418 445 8 495 327 339 70 213 394 462 121 478 43 307 108 229 49 291 131 188 254 507 428 471 89 258 265 288 19 475 227 385 134 247 192 217 150 437 231 412 33 100 95 289 62 445 248 305 24 452 63 89 318 446 119 445 14 102 444 460 10 310 76 247 194 206 254 364 233 379 463 490 27 443 130 341 57 190 145 250 121 212 43 63 29 55 49 137 332 480 101 148 83 256 10 207 58 377 192 476 308 472 244 495 73 242 88 453 134 270 209 221 356 463 13 315 69 145 109 380 68 499 205 404 50 443 376 432 166 30…
Output: 122

Example 3:

Input: 478 2844 186 377 383 442 9 28 308 414 26 179 132 408 3 315 170 324 83 222 198 293 418 444 115 432 11 73 110 370 79 152 198 329 200 316 8 354 85 424 35 358 352 456 101 413 143 241 14 112 145 182 293 378 156 277 159 316 29 459 126 352 345 445 290 420 187 305 106 197 264 443 173 336 35 206 39 199 212 299 171 247 92 102 2 382 249 444 176 364 167 285 189 382 191 202 219 391 301 328 1 386 160 280 205 277 65 371 278 280 5 258 56 441 143 210 181 237 94 213 116 450 92 145 21 312 51 83 303 335 87 444 271 376 15 32 71 139 237 242 72 155 93 408 148 333 213 288 23 183 21 217 93 296 88 156 6 199 182 197 79 80 246 264 133 338 94 263 250 278 337 454 314 403 113 119 163 176 206 312 378 434 94 289 62 95 358 438 229 346 317 414 329 462 144 216 97 122 41 450 245 471 329 474 61 118 181 332 284 319 214 229 33 3…
Output: 1

Constraints:

1 <= n <= 1583; 0 <= m <= 3166; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Separate Camps of the Teal roads - MEDIUM Coding Problem | CodeTikki