CT33361

The Separate Camps of Barkhaven

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Before the gates of the cork grove of Barkhaven close for winter, Sable must finish the corridors ledger - one figure at a time. 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 <= 1767; 0 <= m <= 3534; 1 <= u,v <= n.

Example 1:

Input: 1742 2817 870 1558 329 453 145 1013 332 732 1380 1475 462 1691 708 1021 323 483 850 1478 309 1530 357 757 213 1600 686 905 572 1536 1465 1531 327 1476 1191 1640 17 1211 1180 1240 56 1403 441 1115 386 867 69 1595 956 1640 859 1636 574 1382 586 1608 46 1125 499 1678 30 1586 1181 1442 190 1095 411 1205 522 612 390 1577 365 1034 933 1393 1030 1240 67 924 300 1430 1016 1134 1162 1677 995 1423 314 410 129 446 366 648 86 984 1068 1159 1061 1414 499 990 103 749 181 1023 511 1105 1265 1597 1105 1518 1004 1447 109 1616 835 1319 328 1307 180 1736 250 344 452 920 601 773 882 1128 340 1729 555 852 53 1612 245 562 409 1717 326 1110 4 1707 364 1307 1002 1191 252 423 928 1050 40 1308 909 1676 268 1443 383 904 178 946 1539 1734 1110 1658 94 121 699 1383 234 581 502 1017 519 771 727 1583 1223 1562 82 143 24…
Output: 65

Example 2:

Input: 631 2647 164 303 114 554 22 93 185 254 318 566 173 196 21 582 206 478 67 336 163 557 283 397 93 243 53 365 516 569 147 614 407 487 133 441 277 345 46 481 489 624 462 565 302 305 409 508 124 330 135 235 464 473 108 303 490 568 79 487 208 431 115 518 238 438 226 379 85 255 88 162 150 249 191 469 484 499 303 616 100 336 256 602 191 307 126 443 5 117 340 347 279 470 65 470 259 613 127 335 405 550 107 626 469 623 69 604 15 584 425 523 20 390 288 425 414 586 362 625 345 414 7 547 39 282 511 622 42 449 109 374 43 484 33 408 514 547 487 517 168 249 13 158 135 203 200 561 183 492 351 549 330 476 326 414 32 308 73 225 3 457 434 557 52 250 283 288 265 322 232 449 112 318 298 471 114 135 42 589 134 481 510 627 144 580 421 454 310 519 359 612 327 449 273 274 238 513 478 526 408 529 275 310 30 191 150 6…
Output: 1

Example 3:

Input: 1503 2444 44 167 341 846 569 906 169 623 1189 1278 850 1497 392 1188 120 761 413 1372 447 965 725 919 984 1017 394 1110 484 1389 537 848 293 622 605 843 808 1169 598 909 735 1056 440 470 522 1112 534 911 362 772 1152 1433 329 1281 436 846 446 615 1208 1479 110 803 71 703 356 1024 1051 1147 381 587 687 888 1072 1106 605 657 201 1219 163 1345 559 1058 658 1482 60 1480 241 254 931 1072 968 1329 184 296 403 550 206 1223 296 1321 109 710 642 1192 459 1080 596 681 551 657 86 772 522 722 441 1280 172 710 302 1170 470 621 1438 1441 810 873 222 827 1136 1392 571 1339 222 559 721 1390 146 780 662 1149 471 1240 503 1066 345 773 183 1489 991 1359 36 1460 278 936 533 1079 431 1092 739 1093 14 166 122 1148 28 217 35 1016 758 950 709 1285 157 914 564 1074 318 1416 37 1330 265 436 530 1264 208 1301 214 76…
Output: 62

Constraints:

1 <= n <= 1767; 0 <= m <= 3534; 1 <= u,v <= n.

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