CT44235

The Twilight Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Theo runs the cellar at the fox den of Rustwood. 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 <= 1996; 0 <= m <= 3992; 1 <= u,v <= n.

Example 1:

Input: 778 1756 35 209 126 192 611 634 293 470 337 582 128 242 313 766 611 694 98 278 241 643 85 188 344 549 60 776 149 427 260 681 158 241 23 387 30 346 79 295 443 740 549 698 335 514 138 772 345 431 102 713 202 530 120 548 173 576 117 140 223 278 560 655 31 591 318 769 67 361 141 745 542 746 468 658 379 456 513 700 93 517 634 657 108 373 62 440 225 346 52 123 445 604 471 551 610 758 48 279 195 511 695 729 156 408 329 675 353 744 490 514 106 582 219 434 210 342 454 496 432 440 135 563 299 681 533 686 103 529 189 706 409 676 84 191 287 533 83 653 322 631 11 319 37 567 443 659 157 263 409 728 313 695 127 280 98 724 207 454 523 661 65 391 169 738 31 347 258 757 602 773 384 490 513 562 103 358 30 743 224 378 138 577 88 714 245 675 662 671 234 451 262 587 458 632 401 711 767 778 516 706 330 677 448 4…
Output: 8

Example 2:

Input: 1487 3082 1004 1250 286 845 513 768 207 746 567 1220 380 639 14 1303 652 1138 922 1005 811 1246 523 753 563 993 187 658 175 254 693 997 1055 1303 1198 1318 1418 1438 108 520 100 1443 326 1160 387 1323 316 802 225 1111 597 1437 896 1026 59 972 849 1402 349 850 557 844 460 600 538 727 1095 1384 117 1366 197 554 686 1348 1005 1201 1359 1455 475 1316 421 1483 675 969 1263 1432 457 842 117 166 751 1180 842 1113 34 1409 439 883 890 1234 145 1350 151 1056 835 1181 434 1232 1069 1275 642 897 247 422 229 842 763 1084 586 710 1448 1480 320 1403 1190 1195 448 450 811 840 555 707 1291 1321 121 385 96 488 385 1118 655 1361 303 908 366 1017 177 1150 851 1045 624 859 723 755 537 920 542 551 588 1483 100 1277 43 1170 560 586 465 1063 449 479 67 148 1009 1261 532 552 1118 1446 403 819 174 818 699 1435 1113…
Output: 22

Example 3:

Input: 761 3583 378 544 393 468 500 567 384 588 191 341 211 284 77 172 217 455 275 285 418 477 374 575 624 695 11 135 319 530 43 438 234 586 69 390 271 694 244 550 336 731 248 361 672 709 387 563 78 739 344 458 276 683 287 639 38 447 114 271 129 459 56 69 16 332 596 662 175 571 186 751 162 209 427 591 306 507 66 180 231 585 565 747 456 476 31 219 164 599 1 369 360 464 102 125 9 238 304 696 74 371 341 419 134 713 361 613 257 485 73 421 347 519 180 304 535 550 139 649 190 749 121 331 475 652 587 628 520 725 132 433 441 679 358 509 366 672 45 397 113 509 221 731 334 633 591 597 527 657 506 700 560 681 315 404 3 506 88 161 151 506 394 436 91 433 56 280 70 489 377 507 2 362 13 143 568 597 212 505 278 368 320 523 563 757 483 577 364 534 439 540 84 563 223 557 315 749 433 500 18 178 367 659 270 589 506 …
Output: 1

Constraints:

1 <= n <= 1996; 0 <= m <= 3992; 1 <= u,v <= n.

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