CT33653

The Nacre Bay Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Every season at the pearl fisheries of Nacre Bay, someone must secure the caravan contract. This year the task falls to Leon, armed only with the roads register. 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 <= 1417; 0 <= m <= 2834; 1 <= u,v <= n.

Example 1:

Input: 282 451 34 202 146 252 25 206 60 282 46 101 93 185 2 198 63 118 166 167 15 179 66 185 110 194 178 252 13 241 27 76 84 181 41 92 81 95 182 217 224 243 17 52 12 23 42 279 107 144 153 179 116 222 195 254 25 192 165 232 7 238 62 220 43 113 75 210 142 240 25 145 45 219 76 229 154 227 19 38 151 247 33 239 21 204 205 236 91 98 31 102 182 274 14 34 132 162 50 220 167 229 8 173 21 241 90 106 5 115 73 109 2 239 43 57 238 240 164 251 38 75 57 81 7 120 241 249 39 191 250 267 7 145 125 217 38 133 7 142 178 202 148 266 42 255 143 202 177 257 153 214 223 251 51 171 250 277 223 279 45 60 1 191 48 239 133 219 133 243 171 255 43 121 104 257 115 237 102 190 26 251 170 265 14 146 94 173 63 64 91 100 99 269 47 84 2 122 118 244 126 165 120 207 214 222 94 255 68 220 107 186 130 163 236 252 155 259 207 269 4 189 …
Output: 12

Example 2:

Input: 932 2176 457 813 283 581 101 744 258 902 477 725 611 797 269 642 292 355 433 478 419 740 119 873 23 288 186 593 619 634 97 383 237 665 42 778 891 916 169 831 74 874 319 594 344 565 139 433 135 386 163 385 146 242 345 553 167 363 245 464 693 914 88 609 23 630 29 915 496 864 628 859 360 462 1 3 303 597 5 890 338 651 116 845 591 761 94 808 430 500 851 910 386 459 319 858 111 389 164 686 54 536 103 245 277 342 720 827 266 778 242 770 369 577 117 478 7 141 523 887 389 889 591 930 408 606 14 649 360 593 634 665 172 507 124 873 227 446 3 243 505 754 548 768 255 365 1 152 22 696 181 310 565 756 37 610 162 365 461 867 168 842 77 274 8 305 150 713 435 616 182 848 299 818 244 690 203 815 716 820 880 907 64 390 335 725 344 460 683 710 541 693 467 932 145 669 62 430 218 676 455 623 395 890 28 434 360 4…
Output: 10

Example 3:

Input: 636 1482 343 430 104 432 58 560 55 371 285 506 81 633 275 579 481 523 435 535 91 489 236 558 158 421 407 496 251 288 207 588 59 620 196 251 39 320 71 299 263 634 234 280 48 463 391 604 226 603 231 281 200 376 370 602 111 305 335 523 62 272 332 451 104 500 59 89 310 595 503 581 181 343 18 595 196 570 118 605 49 405 110 141 84 371 386 501 122 384 225 459 388 409 342 586 153 223 248 445 161 431 37 168 205 355 95 484 219 222 92 374 1 27 251 470 97 238 548 568 135 163 259 592 508 630 360 470 89 213 186 227 612 636 250 515 327 444 536 613 402 418 133 351 171 353 244 471 259 525 440 443 381 558 83 378 168 432 5 246 241 244 56 120 156 324 173 611 582 594 299 400 383 624 70 584 297 494 66 477 228 606 175 378 459 503 313 541 361 496 6 223 1 567 23 95 281 457 244 457 284 427 79 284 70 88 214 474 152 …
Output: 4

Constraints:

1 <= n <= 1417; 0 <= m <= 2834; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.