CT55128

Shimmering roads Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the river town of Willowford opens only for a perfect tally of roads. Alaric means to find out. 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 <= 3185; 0 <= m <= 6370; 1 <= u,v <= n.

Example 1:

Input: 1308 4866 287 622 624 661 524 835 159 1178 581 592 797 980 843 973 462 522 770 1248 893 1040 141 901 109 631 871 1121 710 728 189 858 781 965 903 1156 124 571 398 554 430 657 379 1047 44 948 383 1154 461 1018 193 661 667 1219 212 1108 249 855 1003 1261 374 552 485 858 701 837 572 1179 195 859 359 724 218 605 39 903 937 1219 217 246 180 739 357 607 3 863 518 787 138 853 201 1231 1086 1201 1035 1183 521 768 19 820 184 403 355 1302 503 1070 420 1057 109 474 262 1078 612 786 61 436 482 814 948 1240 591 848 788 849 140 166 856 1052 804 982 539 1103 658 1130 788 964 491 1103 29 41 735 1247 758 1116 156 1085 353 924 472 548 392 485 774 1058 863 1000 547 878 180 385 450 797 44 152 32 227 123 375 109 730 41 88 447 780 270 1168 149 1299 747 915 285 632 617 820 315 1269 918 1234 173 569 673 818 21 51…
Output: 2

Example 2:

Input: 782 902 69 113 137 721 320 725 74 477 195 589 47 469 500 555 241 558 21 708 266 324 311 678 149 664 17 682 295 780 328 623 181 632 355 561 196 332 230 576 264 515 102 677 101 410 619 721 1 334 333 438 124 710 347 571 282 619 36 175 515 754 86 404 357 582 64 142 276 381 334 340 427 590 260 539 73 617 480 661 186 635 236 773 678 708 482 747 593 762 296 350 421 459 170 769 61 137 74 256 316 418 59 230 150 682 132 337 50 69 518 695 4 248 622 641 386 663 179 205 402 447 473 552 83 87 129 652 348 674 65 730 6 617 390 547 105 239 206 465 490 497 221 602 449 740 34 663 5 414 80 200 23 189 365 545 216 502 539 757 218 724 284 312 438 651 371 438 605 608 687 768 490 614 9 479 130 350 79 496 230 459 68 698 550 693 164 629 175 392 29 222 172 354 377 616 70 686 656 697 29 465 162 425 449 631 74 623 237 …
Output: 81

Example 3:

Input: 441 2756 11 285 134 229 84 158 354 395 399 432 199 227 105 294 161 358 159 298 398 413 345 356 124 182 71 390 256 371 21 309 305 420 135 306 64 78 228 396 301 325 80 132 255 273 127 206 82 107 153 378 287 400 16 59 195 317 148 218 240 302 347 373 205 282 197 292 164 380 23 212 198 218 33 404 276 397 288 335 195 226 106 435 127 352 59 65 316 410 329 378 177 335 136 328 106 298 68 80 15 238 176 428 107 437 1 328 14 374 235 283 45 168 96 355 198 304 231 375 74 159 275 435 152 308 194 307 172 431 93 270 49 78 153 164 142 367 36 184 112 357 2 135 36 373 2 358 333 361 142 176 1 16 353 436 29 393 351 408 129 291 113 168 31 376 87 265 75 250 99 197 57 418 175 367 249 335 334 349 239 354 237 348 261 350 72 371 167 298 31 167 90 303 130 273 294 349 134 339 229 269 172 247 47 354 263 304 135 292 354 …
Output: 1

Constraints:

1 <= n <= 3185; 0 <= m <= 6370; 1 <= u,v <= n.

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