CT39764

The Separate Camps of the Crystal tunnels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The surveyor Yuri has been asked to rebuild the damaged itinerary. On the desk lies a long table of tunnels readings. 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 <= 1695; 0 <= m <= 3390; 1 <= u,v <= n.

Example 1:

Input: 1512 811 1029 1177 672 675 111 336 183 909 241 447 34 1264 971 1038 205 671 197 1072 1262 1447 80 442 556 943 233 462 728 843 403 1064 637 1276 525 700 101 406 623 1141 1099 1198 89 1053 283 1233 752 1139 1024 1264 409 1486 897 1396 825 1143 1252 1292 322 1179 414 930 115 794 566 1121 100 795 398 900 370 884 249 430 594 1511 287 981 517 1097 1 707 290 832 425 1495 79 516 305 892 362 1300 5 698 869 1475 201 1353 484 1105 832 1234 705 761 1135 1418 705 1375 772 865 533 1284 1006 1181 631 1401 231 1160 163 391 318 708 649 914 459 698 614 1157 242 353 209 321 792 1193 109 838 491 640 154 911 324 350 286 632 1167 1452 15 394 315 1125 1373 1479 1174 1364 119 1422 812 1463 611 1172 836 1009 37 45 272 988 621 1483 192 303 1273 1491 382 1320 64 456 430 813 1379 1416 446 744 179 506 168 408 928 1459…
Output: 704

Example 2:

Input: 1240 3343 286 818 128 176 785 1136 111 382 192 311 755 1231 580 860 438 822 844 880 357 887 486 781 234 243 625 658 236 313 178 267 21 986 191 467 15 273 766 997 347 1111 569 1145 57 1130 225 719 11 249 467 587 257 571 6 94 166 272 646 1066 147 936 264 518 49 611 312 806 588 699 860 939 276 1144 540 912 787 948 51 696 112 496 450 1181 210 682 574 620 476 746 59 803 418 585 763 1220 34 283 399 913 729 1080 190 907 795 1061 543 546 586 900 408 491 484 718 170 623 25 242 643 711 134 228 388 1066 317 1150 400 584 444 1186 403 469 382 1140 339 593 21 691 116 128 420 1006 179 667 121 987 182 1144 804 1044 550 796 711 756 83 226 942 1107 544 725 300 452 851 897 195 921 215 251 22 303 161 963 528 734 249 879 249 758 27 254 460 1236 711 715 120 1126 464 1067 580 1004 433 844 181 373 35 217 679 1120…
Output: 10

Example 3:

Input: 1407 109 7 12 848 1223 1069 1127 1005 1394 896 1403 1230 1359 162 595 241 549 79 340 129 583 431 848 246 739 205 1333 58 525 466 1319 402 1170 792 1074 935 1250 86 714 301 1358 192 1190 83 700 971 1075 722 1143 803 1208 184 704 1074 1400 226 1189 505 1047 140 462 463 1236 832 967 119 700 214 602 406 563 439 1095 791 874 418 494 346 1111 841 1159 736 1130 453 1167 730 1159 411 1332 339 551 284 542 560 1194 270 912 928 1155 172 1138 301 1282 177 606 1203 1250 287 1179 736 817 500 1010 463 847 778 973 88 1162 289 1383 988 1226 1024 1221 629 695 594 853 374 1237 732 1316 872 972 346 1120 885 1104 792 844 1030 1054 516 1142 62 709 330 717 710 1131 633 743 509 1226 776 974 72 1108 536 1006 212 901 300 824 205 427 40 589 212 507 803 1227 683 1038 554 1023 102 199 115 663 90 340 911 1370 476 1028 …
Output: 1298

Constraints:

1 <= n <= 1695; 0 <= m <= 3390; 1 <= u,v <= n.

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