CT36943

Steward's tunnels Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Steward inherited the boathouse at the gull cliffs of Screech Point along with its curious bookkeeping system for tunnels. Time to make sense of it. 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 <= 2227; 0 <= m <= 4454; 1 <= u,v <= n.

Example 1:

Input: 436 1229 205 330 147 243 340 363 39 350 12 199 190 199 99 241 181 324 111 124 25 255 119 430 171 397 79 191 161 424 45 140 212 368 359 393 100 168 165 243 50 339 262 390 181 325 38 166 219 353 125 175 42 219 386 395 155 407 96 419 254 308 133 390 408 435 82 197 164 316 161 321 60 435 120 405 281 333 82 139 241 343 87 127 11 400 259 371 72 126 94 197 91 133 159 179 161 349 232 320 245 360 46 141 33 59 143 256 12 239 180 282 174 220 225 280 254 316 30 351 214 352 156 374 23 350 220 416 154 293 177 254 276 362 195 251 97 386 320 340 211 328 182 367 84 200 3 282 144 380 27 180 224 398 308 316 35 200 18 131 79 196 27 362 233 322 108 326 161 198 30 180 221 288 18 303 2 57 47 289 72 177 231 382 45 375 7 240 225 376 341 413 226 381 122 362 125 146 26 172 1 283 38 161 93 205 163 373 31 226 248 388 …
Output: 2

Example 2:

Input: 333 2232 28 212 163 175 132 214 3 29 260 266 238 320 261 275 146 318 62 149 39 305 34 247 194 236 79 95 172 204 141 213 38 308 143 295 77 271 196 317 67 107 79 139 206 252 127 241 80 168 48 230 138 321 118 329 151 318 116 219 51 258 181 289 3 251 26 150 69 192 120 128 94 311 90 127 45 173 228 236 153 251 36 186 17 67 61 318 94 328 143 214 95 104 165 185 167 302 36 271 11 76 201 223 15 71 74 255 75 293 274 300 81 223 251 276 27 65 116 241 180 231 32 122 15 290 9 190 30 279 39 102 150 265 305 327 218 296 65 214 43 220 304 332 211 301 134 230 232 315 106 171 201 292 131 171 268 269 196 231 176 288 288 311 30 33 5 220 22 110 100 169 141 333 70 141 238 260 190 303 101 259 29 321 153 157 183 218 172 293 73 239 276 330 226 333 79 246 245 303 132 293 29 175 59 125 57 171 36 318 12 141 144 249 111 …
Output: 1

Example 3:

Input: 1320 4141 213 377 261 1075 95 184 155 1001 796 805 298 619 234 1082 548 752 1026 1074 320 408 828 1004 211 290 90 834 645 672 48 568 308 793 691 849 455 822 38 299 519 656 524 897 30 774 638 977 983 1162 438 1285 823 1050 168 219 47 138 1117 1197 839 1263 1146 1255 203 593 1144 1234 301 1131 166 1051 93 973 199 771 1014 1279 130 301 750 770 1045 1304 117 1176 388 1248 132 1299 537 1162 959 1103 684 710 690 869 175 1204 165 232 96 480 95 916 249 1232 265 836 300 900 479 1286 514 1240 54 1289 170 351 150 835 213 274 363 859 568 756 577 694 758 1217 640 666 1210 1230 183 822 879 1137 999 1297 332 716 166 731 298 688 633 871 1073 1116 1090 1152 974 1056 1087 1128 217 655 303 922 682 1279 79 808 1058 1089 963 1209 678 881 558 1188 629 1259 617 1278 108 221 256 1267 1123 1139 1114 1124 320 386 2…
Output: 2

Constraints:

1 <= n <= 2227; 0 <= m <= 4454; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Steward's tunnels Separate Camps - MEDIUM Coding Problem | CodeTikki