CT55471

The Hammerfall Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Xavi the clerk watches over the anvil district of Hammerfall's stores of routes. A careful computation stands between order and chaos. 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 <= 1990; 0 <= m <= 3980; 1 <= u,v <= n.

Example 1:

Input: 513 1493 41 137 58 453 212 510 344 459 387 399 22 23 129 401 38 401 323 350 176 308 335 444 156 250 351 473 242 365 436 460 309 419 304 315 306 347 3 199 180 242 14 218 294 397 140 153 280 492 239 281 397 439 177 396 145 257 357 387 11 210 132 187 105 479 138 212 3 288 248 314 347 487 65 153 295 432 97 465 267 446 166 438 18 72 65 86 116 313 34 386 93 169 140 162 42 91 316 362 5 35 310 369 314 338 13 61 76 259 151 295 288 451 173 307 246 255 208 216 163 278 250 422 120 128 326 469 412 502 278 351 24 424 110 486 21 160 85 237 127 471 15 293 319 360 110 176 52 439 86 285 325 416 41 307 105 450 6 375 72 462 135 264 428 475 330 356 295 415 40 230 62 240 182 185 56 253 73 313 72 125 51 222 76 449 77 163 115 169 32 144 301 311 162 399 247 262 63 351 285 395 146 287 232 265 118 370 166 424 227 33…
Output: 2

Example 2:

Input: 230 1229 45 103 180 230 76 77 89 172 112 185 85 87 54 196 137 197 51 175 65 153 12 210 116 132 211 226 51 192 38 157 83 106 43 152 109 216 57 58 125 203 79 85 9 23 85 156 152 186 17 227 88 177 63 170 8 169 208 225 107 138 46 92 87 137 117 201 16 218 110 145 25 67 117 170 45 84 89 135 145 207 121 206 98 182 75 149 117 119 2 116 34 129 173 229 108 193 196 207 17 53 41 228 37 211 31 57 2 22 59 225 97 164 64 91 57 117 112 214 65 81 2 191 12 99 163 230 80 98 42 147 37 157 94 144 167 210 194 228 34 114 164 206 50 200 182 230 161 188 151 187 117 196 72 156 207 229 17 22 6 55 7 11 193 216 130 228 39 121 146 149 167 181 46 130 38 125 34 191 89 156 75 103 44 172 94 189 120 188 41 122 144 197 37 52 30 95 14 52 122 221 32 89 21 99 104 175 171 181 9 61 78 158 147 166 39 178 85 139 87 226 63 95 92 118 2…
Output: 1

Example 3:

Input: 1269 1708 242 605 427 440 610 1081 485 945 553 590 943 1078 122 936 70 926 638 1115 703 1042 307 704 1061 1252 28 664 825 1251 809 1254 296 567 218 813 162 758 624 719 610 1000 595 732 157 708 261 1256 7 698 162 745 98 923 469 561 970 1184 627 1204 731 931 60 1052 17 1182 554 1032 392 470 439 1207 541 783 227 1173 878 933 129 193 469 859 237 254 1224 1239 34 563 618 1102 1167 1183 322 864 404 965 80 1035 64 116 480 789 771 896 331 1150 774 1163 536 921 456 1148 392 1042 602 640 633 895 537 687 18 344 201 639 298 354 111 832 242 840 417 1017 313 1079 25 639 7 589 930 945 759 861 979 1151 798 1145 214 520 108 717 614 623 463 1164 516 1239 409 609 120 413 697 1107 716 1045 741 1073 591 1196 584 894 166 798 671 1236 49 288 264 745 52 712 332 1152 75 1174 118 768 138 215 782 1064 692 1199 858 1…
Output: 89

Constraints:

1 <= n <= 1990; 0 <= m <= 3980; 1 <= u,v <= n.

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