CT36597

Lysander's Separate Camps Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the basalt cliffs of Obsidian Shore with crates of canals, and Lysander the bookkeeper must account for every last one. 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 <= 1611; 0 <= m <= 3222; 1 <= u,v <= n.

Example 1:

Input: 1301 2620 993 1004 587 727 1257 1299 404 1127 400 985 577 778 216 1167 636 1080 656 936 484 714 343 1024 1154 1242 387 1249 149 740 897 983 430 655 494 865 431 1117 293 297 1064 1168 620 815 300 692 67 994 101 1155 211 767 288 1083 856 1017 625 983 1082 1139 477 585 893 983 9 723 292 366 705 1138 197 893 914 1038 964 1071 408 992 675 964 559 1141 770 974 64 608 845 1197 393 1126 730 970 5 784 576 664 541 1214 801 903 220 776 88 797 745 1097 326 923 825 1033 105 1046 181 1100 806 974 192 988 645 1156 667 801 383 1269 433 1111 610 1262 150 1300 249 253 217 1042 331 386 707 926 54 770 736 1247 298 550 409 860 338 1075 218 1166 236 1002 629 1049 1103 1188 456 541 676 1206 234 747 261 862 664 1071 978 1167 552 1263 177 906 555 802 572 855 106 832 1119 1294 767 998 373 410 302 1240 608 762 699 9…
Output: 16

Example 2:

Input: 233 968 18 21 46 122 62 65 9 193 104 133 9 73 95 106 49 144 180 213 2 150 52 88 63 184 117 149 5 86 164 166 131 159 191 201 37 99 140 162 118 181 10 206 143 145 15 45 151 207 134 175 120 157 49 111 32 185 29 46 136 208 113 210 60 94 3 110 41 124 128 165 59 220 137 172 18 100 93 231 62 64 107 168 3 213 132 188 157 206 82 157 7 26 19 148 143 171 50 196 71 105 16 103 10 112 149 159 96 144 108 171 19 63 21 24 17 107 87 219 15 107 57 103 44 77 56 217 7 147 123 218 11 81 178 189 12 113 122 208 53 163 140 188 4 41 6 192 18 106 79 224 65 169 24 231 126 146 95 196 164 217 47 198 39 163 81 89 31 217 133 167 56 96 52 122 3 56 94 114 36 144 134 221 8 64 139 215 43 49 112 141 55 229 41 51 72 232 110 160 35 130 131 140 4 194 37 211 21 136 20 54 143 198 62 163 185 227 108 124 44 222 60 118 135 211 29 192…
Output: 1

Example 3:

Input: 527 33 18 523 153 271 193 520 424 502 251 485 28 375 141 211 223 474 312 356 171 239 125 263 15 30 368 514 146 180 227 289 372 474 15 506 156 227 152 259 229 409 22 128 269 474 19 39 94 449 470 519 109 118 23 193 371 509 21 488 210 363 84 426 103 106 348 368
Output: 494

Constraints:

1 <= n <= 1611; 0 <= m <= 3222; 1 <= u,v <= n.

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