CT34804

Axel's Ledger of corridors

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the poppy fields of Scarlet Plain, Axel records each corridors in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1076; 0 <= m <= 2152; 1 <= u,v <= n.

Example 1:

Input: 481 1985 186 255 40 324 101 330 84 107 105 217 10 380 249 378 256 301 303 306 256 435 32 299 72 349 4 275 281 375 81 292 87 184 436 464 251 424 4 302 360 471 202 303 386 401 128 225 104 285 14 52 216 258 110 363 79 349 260 290 41 466 255 371 106 380 319 389 201 440 68 238 213 295 57 469 359 451 220 267 210 249 162 425 58 362 323 362 15 60 105 411 311 315 134 341 181 233 147 478 88 254 95 429 96 297 105 340 18 453 118 294 119 139 206 234 369 371 21 269 269 461 66 233 200 213 180 420 50 281 50 252 24 160 146 242 86 463 92 187 3 239 27 298 206 330 54 207 120 268 6 411 227 432 113 140 111 370 132 430 32 94 121 475 149 450 148 189 55 447 16 196 25 50 403 405 434 446 128 389 12 124 222 319 61 258 43 410 77 439 344 386 270 341 196 219 337 438 294 437 121 440 34 119 337 367 14 368 52 358 168 454 8…
Output: 1

Example 2:

Input: 348 429 14 340 292 329 104 154 89 156 23 218 98 242 53 326 215 286 52 347 319 320 168 240 99 258 158 199 34 62 159 270 5 76 158 213 84 216 163 211 235 262 35 148 126 306 147 245 7 133 263 316 205 257 151 318 176 286 63 299 101 248 152 227 318 344 86 115 25 332 219 270 144 319 127 185 108 120 189 266 255 276 1 286 130 202 181 257 48 119 174 311 140 323 254 298 188 228 21 281 225 232 65 198 104 196 165 343 80 227 283 333 51 157 213 226 240 312 202 277 131 306 114 335 32 327 16 256 117 273 58 177 204 205 87 123 82 128 154 259 298 343 125 231 139 141 166 325 153 188 35 292 265 270 150 182 83 166 32 71 37 283 236 332 168 346 64 283 8 11 146 217 167 263 86 161 322 337 54 228 32 172 109 219 106 119 62 201 160 344 75 197 16 23 148 184 136 278 34 293 20 256 104 273 43 229 18 163 10 259 129 255 33 3…
Output: 37

Example 3:

Input: 729 1338 567 697 284 686 251 662 251 559 72 350 278 324 24 441 266 341 376 624 353 717 393 441 647 655 177 240 51 410 495 637 66 341 299 527 85 660 171 236 278 409 24 248 50 318 192 597 339 470 263 642 435 565 407 566 179 485 61 635 101 310 228 679 262 543 655 690 116 281 82 310 497 639 655 663 335 478 682 684 218 441 335 378 338 614 112 575 58 336 97 151 231 345 353 700 134 137 138 291 352 591 219 623 70 460 227 395 16 669 292 396 167 432 261 571 417 623 497 721 79 271 216 385 75 437 279 350 544 547 45 79 306 688 60 434 86 624 227 703 47 414 212 500 603 694 231 269 251 438 174 660 221 584 207 508 92 268 405 704 209 550 45 181 415 555 502 566 358 458 101 410 232 283 505 596 318 420 154 333 13 534 72 288 537 553 298 379 209 541 355 674 224 471 182 243 327 674 600 618 385 707 79 514 221 468 …
Output: 14

Constraints:

1 <= n <= 1076; 0 <= m <= 2152; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Axel's Ledger of corridors - MEDIUM Coding Problem | CodeTikki