CT38679

Hema and the Ivory tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Hema runs the timber yard at the foggy moor of Greyfen. Today the books show a list of tunnels, and the numbers must be worked out before sundown. 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 <= 3216; 0 <= m <= 6432; 1 <= u,v <= n.

Example 1:

Input: 657 4117 360 648 339 470 113 334 59 156 77 546 239 300 104 575 289 482 87 222 77 300 308 457 128 445 155 402 10 21 82 640 32 575 94 223 70 555 311 554 60 354 116 567 87 261 401 612 389 610 333 536 375 396 233 328 51 305 49 547 366 425 230 435 111 326 167 535 211 251 74 575 490 513 34 262 347 562 351 544 143 189 30 266 25 423 121 427 54 584 180 592 466 533 361 566 105 254 400 449 362 502 398 651 252 537 76 409 51 352 41 225 172 461 299 642 169 512 272 544 140 599 59 110 114 257 207 457 100 251 320 336 151 431 573 651 421 474 107 163 58 433 328 564 152 327 105 230 5 322 306 615 90 263 76 615 236 491 533 626 394 403 388 609 239 408 106 127 313 357 105 501 139 553 309 620 46 179 218 611 102 343 182 191 593 603 38 557 4 206 115 591 406 489 213 226 277 291 176 317 326 546 413 579 375 518 7 552 2…
Output: 1

Example 2:

Input: 541 5971 184 515 41 485 255 312 63 314 361 465 295 428 360 492 195 208 17 539 264 513 143 188 83 233 53 167 20 35 107 189 77 243 13 462 321 403 351 411 413 420 150 432 270 491 99 299 216 398 118 152 84 233 339 540 237 491 354 383 490 535 318 494 369 491 92 327 195 533 142 262 44 59 87 387 465 485 291 482 170 289 37 174 150 209 285 526 48 124 145 499 175 199 112 492 349 537 144 452 177 476 106 307 454 523 8 83 94 199 289 380 261 316 78 410 113 475 169 389 208 480 226 430 191 333 245 345 337 409 181 464 63 222 117 333 383 396 122 406 268 371 196 493 13 278 51 103 236 282 185 345 246 531 82 244 356 438 300 317 247 470 6 396 63 418 129 251 122 141 303 514 338 385 221 477 316 383 34 482 146 378 105 451 296 424 259 504 42 211 37 213 131 150 201 252 1 365 362 433 221 421 239 470 307 328 95 230 33…
Output: 1

Example 3:

Input: 941 1376 374 539 188 392 631 755 245 457 36 631 523 601 386 489 4 387 331 670 575 788 12 262 613 903 221 729 387 688 221 703 675 912 448 589 881 911 546 909 206 826 190 400 93 715 780 918 334 702 801 811 241 768 645 845 90 453 653 732 349 537 148 448 749 922 70 861 147 390 436 724 723 796 456 610 681 685 65 891 768 851 236 493 107 195 44 294 268 662 43 844 110 390 17 546 421 907 767 886 409 679 386 685 652 666 230 332 633 671 473 730 621 936 195 508 84 665 545 845 92 402 170 288 188 630 615 641 525 838 108 146 433 736 169 466 330 875 399 713 72 404 178 845 14 769 6 918 201 631 418 634 239 887 723 909 75 649 166 570 456 586 481 548 396 409 738 829 576 706 111 551 385 863 528 588 99 568 86 325 122 542 410 533 129 153 604 805 133 878 677 725 360 737 105 370 750 827 127 359 284 288 134 880 389…
Output: 55

Constraints:

1 <= n <= 3216; 0 <= m <= 6432; 1 <= u,v <= n.

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