CT30954

Baron's roads Separate Camps

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The council of the canyon post of Redrock pays by the answer, and Baron intends to earn it. First: the full register of roads. 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 <= 1751; 0 <= m <= 3502; 1 <= u,v <= n.

Example 1:

Input: 781 1363 148 343 117 405 221 399 36 483 647 763 159 357 23 371 41 181 215 652 190 540 208 696 45 288 236 716 111 482 16 361 24 249 617 640 217 438 393 408 409 646 328 478 210 352 421 667 145 221 137 529 59 571 84 743 483 715 164 549 144 251 26 511 387 395 429 658 176 588 125 306 304 685 72 714 315 668 14 474 133 435 119 562 534 723 467 588 366 559 615 697 70 748 340 497 439 500 76 697 18 639 371 378 212 595 238 535 264 540 411 566 579 760 310 447 127 310 507 701 60 627 197 239 552 652 320 754 394 662 231 599 45 179 3 539 161 484 690 776 110 389 383 532 54 191 84 220 49 412 307 455 443 628 114 768 102 264 447 633 36 659 76 385 116 460 617 624 169 366 160 192 16 606 565 758 100 730 601 694 233 761 641 750 326 592 505 524 20 761 43 643 375 781 254 377 297 446 35 227 493 747 46 647 72 284 154 …
Output: 20

Example 2:

Input: 429 2420 187 287 177 201 411 424 43 388 52 316 242 343 357 389 57 182 130 166 44 168 51 201 170 185 204 341 341 362 18 404 41 43 178 344 143 162 192 299 89 288 135 300 110 186 244 300 18 106 84 179 167 254 27 222 204 301 76 367 55 247 47 73 146 427 269 374 90 217 72 219 119 390 137 397 138 212 194 324 110 144 30 342 4 260 129 147 268 271 407 412 97 374 205 213 220 309 131 133 202 425 8 27 135 193 206 320 19 75 133 276 92 279 172 228 23 404 107 207 80 189 25 427 87 284 106 289 66 342 12 254 186 265 133 242 337 403 216 306 294 428 391 399 67 165 6 399 4 233 221 348 113 280 205 344 260 378 52 109 252 310 242 298 58 170 273 396 234 298 47 422 144 261 110 290 268 381 220 308 62 100 11 406 65 370 294 335 110 263 37 360 1 228 14 275 76 219 142 399 188 218 169 263 57 373 189 353 133 232 74 155 156…
Output: 1

Example 3:

Input: 1007 734 670 776 569 858 504 749 237 283 579 626 109 484 349 758 409 740 129 811 449 969 34 273 30 459 186 636 354 815 3 841 760 828 177 673 369 717 11 500 5 985 370 664 189 634 291 531 159 227 97 466 425 817 166 278 595 970 539 577 6 871 389 437 411 823 205 997 717 998 464 679 394 742 275 983 260 719 567 732 480 925 794 806 290 408 17 795 42 143 227 374 70 365 237 944 14 420 491 494 39 219 64 461 345 992 276 461 342 480 771 986 358 880 75 477 235 916 448 604 414 854 140 226 583 630 811 894 157 957 786 836 811 836 513 779 8 963 396 486 612 702 302 511 478 898 258 853 247 607 681 981 151 865 168 321 67 322 170 720 159 882 116 969 658 703 9 438 545 932 788 872 715 909 288 690 980 994 355 805 21 60 226 776 56 709 195 209 247 769 549 590 125 361 51 842 664 730 136 465 687 699 618 1003 314 602 …
Output: 303

Constraints:

1 <= n <= 1751; 0 <= m <= 3502; 1 <= u,v <= n.

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