CT30743

Xara's bridges Reckoning

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Xara the store warden watches over the tundra station of Whitesnow's stores of bridges. 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 <= 1659; 0 <= m <= 3318; 1 <= u,v <= n.

Example 1:

Input: 368 2681 102 338 88 304 38 76 5 353 207 305 6 274 339 356 255 276 139 351 16 292 54 302 203 321 230 282 13 76 11 18 9 44 170 248 270 305 45 108 152 286 236 355 113 273 37 62 221 281 61 220 176 309 42 78 322 331 130 146 92 329 42 175 76 161 73 304 134 245 66 174 223 352 25 202 81 149 251 334 98 215 229 364 32 182 171 207 56 177 36 230 48 85 118 262 262 311 13 236 152 305 125 197 148 356 176 253 43 139 49 261 57 317 157 231 61 301 5 301 176 333 272 330 14 270 284 287 203 323 106 212 176 356 82 244 50 325 92 351 130 233 104 272 280 350 207 302 245 342 58 357 35 298 183 277 233 303 109 220 199 328 68 233 74 236 288 315 120 288 264 336 102 306 283 366 99 149 9 342 122 229 213 221 90 339 59 343 15 137 154 307 119 166 163 238 125 316 62 356 222 346 135 264 195 335 276 310 279 286 240 323 92 117 2…
Output: 1

Example 2:

Input: 473 2079 311 360 59 450 192 453 18 103 189 433 348 431 40 292 61 182 209 261 257 376 175 280 44 119 32 257 227 464 287 360 253 402 93 136 35 368 145 284 174 245 22 405 380 442 346 388 202 441 204 265 90 276 22 468 404 441 186 188 33 239 330 374 172 392 186 280 200 322 64 259 41 73 204 408 70 111 336 352 112 450 40 150 99 245 352 422 81 321 282 461 172 218 111 368 228 283 27 56 266 323 141 366 102 333 257 457 209 425 364 380 23 245 133 316 243 446 193 463 93 297 174 266 132 460 42 113 66 336 34 153 247 433 174 419 317 357 427 457 58 293 123 182 108 355 121 394 207 327 331 470 134 152 357 376 52 257 271 299 72 388 202 283 354 416 150 427 47 197 82 359 62 423 276 325 237 305 51 245 10 44 221 471 44 195 102 229 5 291 231 410 236 473 247 282 107 455 52 117 42 291 84 397 142 225 3 69 84 279 30 2…
Output: 1

Example 3:

Input: 720 1819 175 273 315 678 166 563 563 564 216 532 458 559 66 147 267 435 51 222 90 345 213 335 64 233 653 701 139 380 59 634 545 596 420 707 460 465 189 527 565 679 299 599 189 544 298 469 232 420 225 418 320 399 362 493 102 653 304 563 48 479 104 242 129 207 79 262 556 606 143 658 343 586 68 169 608 686 91 589 190 616 579 712 428 649 491 541 379 414 141 187 174 295 233 515 118 369 296 298 102 323 459 615 297 650 474 542 49 229 339 634 154 256 225 453 307 488 122 205 421 637 452 483 252 627 305 397 345 711 165 510 579 654 166 566 168 431 362 417 225 680 149 272 653 674 138 582 195 567 54 553 408 533 304 432 20 208 287 708 189 716 58 663 66 280 89 333 170 534 337 366 504 624 463 664 99 238 143 271 68 168 28 431 19 267 125 338 680 695 25 596 166 419 20 552 159 397 126 312 248 615 326 420 43 7…
Output: 5

Constraints:

1 <= n <= 1659; 0 <= m <= 3318; 1 <= u,v <= n.

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