CT49974

The Separate Camps of the Bright roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the cotton rows of Whitewick, Qadir records each roads in a worn leather ledger. The guild wants answers, not guesses. 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 <= 2748; 0 <= m <= 5496; 1 <= u,v <= n.

Example 1:

Input: 2477 3551 147 572 2316 2423 34 2361 766 1487 144 1684 852 934 294 398 240 1071 798 2026 183 1783 767 1026 2305 2343 459 2034 1633 2060 982 2109 751 1595 569 874 1960 2431 1937 2222 526 1900 1240 1813 1316 1836 353 1638 1026 2089 1375 2104 645 2170 1565 2170 414 786 177 2167 90 1856 47 2089 188 510 1461 1659 945 2030 250 518 935 1403 1512 1531 179 780 181 2301 995 2044 1326 1607 604 1983 1327 1771 349 2461 371 1441 343 1338 366 2070 113 1008 322 1844 269 1738 1448 1492 808 2317 2209 2443 384 935 53 177 667 714 580 1427 477 1286 107 1219 51 419 25 521 293 1205 745 1995 1283 1527 325 1158 582 1101 51 1554 507 906 1120 1855 419 2216 2163 2363 2258 2439 1986 2383 237 2455 604 2108 944 2300 1090 2461 1853 1959 255 1770 967 1885 592 2411 639 1115 699 2027 246 2063 334 1987 1224 1963 1326 2186 111…
Output: 158

Example 2:

Input: 741 2748 296 646 403 735 2 229 242 687 208 643 596 671 303 537 146 380 88 588 88 434 77 515 270 486 304 630 501 644 257 630 716 729 186 210 567 590 3 548 225 316 352 663 319 504 273 552 12 439 215 436 493 673 292 424 462 509 553 611 550 566 255 347 429 557 80 159 479 529 44 544 53 259 248 313 123 727 60 556 696 709 132 326 91 278 17 502 531 674 162 462 349 727 412 444 17 535 511 542 61 740 171 495 38 317 321 734 308 356 245 684 408 557 521 728 595 724 203 681 454 636 487 712 65 92 26 698 266 515 318 726 96 317 156 218 231 666 40 620 90 175 232 617 2 115 139 372 126 482 98 322 134 349 231 452 301 661 219 457 264 352 576 691 232 497 359 741 88 719 473 512 116 448 497 510 100 289 362 619 117 676 408 533 304 457 54 682 472 731 381 604 39 446 196 693 261 292 65 240 32 239 76 101 161 261 166 639…
Output: 1

Example 3:

Input: 835 2153 661 711 7 237 84 296 75 809 234 695 388 668 282 701 104 359 359 600 193 570 402 795 175 658 390 817 14 164 476 570 494 733 167 197 13 549 131 339 134 822 53 92 8 790 257 287 330 783 114 265 387 660 192 648 479 780 453 807 225 506 44 97 43 600 30 708 294 785 249 748 345 409 83 258 287 289 312 328 389 775 521 729 73 461 171 427 1 602 317 325 181 594 190 204 547 672 87 559 493 541 253 304 511 522 23 136 263 748 180 590 144 771 141 213 407 590 43 391 47 252 215 834 114 277 410 585 654 677 513 654 588 816 93 111 99 741 105 709 44 232 155 164 651 760 21 56 148 204 422 800 343 530 404 677 260 389 461 681 186 322 152 278 108 383 71 415 77 141 504 590 668 724 138 172 658 692 279 347 36 303 276 480 210 801 326 434 631 688 117 582 38 561 323 398 230 336 177 742 119 468 468 794 219 379 538 60…
Output: 5

Constraints:

1 <= n <= 2748; 0 <= m <= 5496; 1 <= u,v <= n.

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