CT48247

The Separate Camps of Lantern Tor

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the beacon hill of Lantern Tor with crates of tunnels, and Jeweler the customs officer 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 <= 1705; 0 <= m <= 3410; 1 <= u,v <= n.

Example 1:

Input: 393 2330 84 349 214 338 172 347 12 265 71 80 106 233 357 366 139 297 78 368 38 45 107 345 282 301 108 111 88 131 207 340 117 191 121 144 109 297 127 307 55 210 23 180 135 146 8 60 129 148 299 343 178 195 119 373 280 293 197 248 90 146 48 288 111 341 77 373 178 297 44 261 155 222 99 161 313 389 123 300 105 261 106 138 344 358 12 278 21 168 140 258 218 393 160 370 176 208 16 22 70 295 262 306 159 264 42 393 152 374 181 283 30 316 129 279 233 316 47 173 208 292 341 384 28 121 27 162 85 340 73 149 10 254 210 353 160 302 109 112 14 196 239 348 159 179 126 389 149 292 186 369 153 341 157 296 323 332 46 390 250 357 298 345 191 243 174 321 183 185 30 173 47 325 84 253 252 338 17 132 81 223 1 228 195 323 156 271 216 250 16 48 115 253 109 110 23 214 133 369 100 196 95 280 304 313 194 289 105 141 8 3…
Output: 1

Example 2:

Input: 810 1975 267 304 58 543 281 592 107 551 318 698 247 671 106 562 215 527 200 564 91 495 198 527 174 256 210 579 753 790 571 786 379 774 452 573 591 807 296 563 133 356 272 601 6 229 368 719 363 410 721 803 271 528 105 263 711 740 35 572 262 716 180 640 127 174 112 354 207 587 253 507 154 468 421 639 81 500 210 279 273 439 217 409 535 783 36 162 550 592 614 775 433 581 348 720 23 522 90 791 350 742 464 491 96 548 328 391 555 766 513 711 202 321 430 764 451 737 153 695 74 138 322 354 280 502 401 692 76 615 583 661 104 283 22 802 653 802 519 547 467 546 3 463 432 609 469 784 27 424 213 379 48 89 512 637 453 794 249 676 62 720 275 800 469 797 160 670 126 254 476 603 80 350 548 659 329 342 440 740 345 359 233 355 398 671 322 785 610 671 212 273 564 682 34 128 238 675 359 400 341 487 377 668 32 3…
Output: 6

Example 3:

Input: 425 215 218 320 297 414 119 421 100 120 45 105 124 159 57 125 268 369 115 243 17 246 173 343 10 327 303 410 58 127 36 279 209 341 165 399 64 284 3 265 140 393 10 16 160 393 349 369 20 284 261 264 132 188 101 379 285 370 120 414 121 260 59 172 32 213 24 295 62 130 374 411 109 198 194 375 57 172 122 337 173 222 124 325 60 182 168 321 192 408 336 369 80 231 95 165 15 301 90 387 17 336 35 181 14 187 61 221 139 187 217 277 54 424 163 375 223 390 119 251 129 371 196 275 66 214 75 129 223 291 270 340 127 348 182 350 99 221 113 421 252 275 61 77 133 400 8 287 216 390 96 241 89 329 36 220 135 397 209 323 275 281 45 161 77 384 64 281 133 311 21 207 139 408 235 307 245 366 108 137 64 400 23 80 28 44 196 360 86 87 8 184 233 249 414 420 172 355 248 319 112 297 48 280 18 382 63 181 100 165 47 413 85 231…
Output: 211

Constraints:

1 <= n <= 1705; 0 <= m <= 3410; 1 <= u,v <= n.

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