CT40686

The Roving Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the salmon ladder of Rushing Falls, Aria records each routes 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 <= 2109; 0 <= m <= 4218; 1 <= u,v <= n.

Example 1:

Input: 507 4034 150 372 399 457 393 399 14 21 7 316 168 359 17 321 80 262 152 202 166 219 10 496 44 46 230 307 224 295 300 492 84 429 381 463 214 296 181 238 290 342 437 503 97 279 291 343 363 432 227 345 263 487 337 363 297 446 130 267 110 301 182 427 215 285 88 207 54 151 398 501 147 316 156 335 37 383 82 89 66 438 399 497 392 485 117 395 324 473 466 486 14 183 188 450 131 150 306 474 311 359 218 464 108 446 412 415 110 216 90 388 218 357 323 390 60 480 31 293 188 428 75 397 130 176 316 378 408 467 223 262 54 472 316 443 244 330 4 478 265 400 216 469 17 401 402 439 156 330 318 323 3 344 164 494 189 476 272 465 38 499 169 471 45 413 218 339 184 287 108 391 26 152 400 440 91 105 104 202 317 445 155 352 34 272 41 181 134 139 221 250 216 344 128 138 264 429 18 184 5 328 476 491 281 350 264 419 334 …
Output: 1

Example 2:

Input: 1809 2531 424 1160 1096 1721 75 1054 543 619 147 1601 295 1020 437 468 331 874 339 716 126 1206 1323 1763 233 1209 491 885 1052 1331 251 583 322 821 1197 1717 127 317 556 1349 632 721 1176 1765 600 1542 221 458 78 738 544 1772 654 1570 964 1538 29 609 250 781 385 1481 1406 1571 1017 1150 1217 1362 363 654 743 1083 649 823 866 1520 783 1803 366 1737 1169 1317 936 1787 416 1419 65 550 861 1068 913 1458 597 1614 568 1399 61 1606 683 1716 208 1744 1713 1802 351 1651 51 1573 546 1361 832 1760 511 979 667 1400 1030 1113 708 1167 208 1248 1039 1265 1189 1562 631 790 98 338 1209 1623 245 933 236 766 423 1763 1544 1606 1009 1414 1148 1428 413 1614 59 1514 369 838 990 1764 933 1683 759 1359 220 730 1054 1760 1363 1708 870 1549 693 795 579 703 572 1516 1339 1565 1623 1751 1047 1774 1318 1374 836 1310…
Output: 113

Example 3:

Input: 478 2866 121 292 331 369 117 188 59 224 22 103 176 331 52 435 73 146 185 308 130 304 273 420 48 121 41 464 58 107 247 448 315 442 194 301 226 444 265 359 53 58 14 246 39 236 115 401 107 345 235 397 29 366 304 310 241 469 100 201 253 395 70 200 232 322 30 105 107 276 252 342 159 382 151 376 37 385 105 108 86 116 135 217 122 227 306 394 241 312 42 452 179 364 74 376 115 386 176 438 74 358 307 353 138 209 129 282 154 431 50 366 161 254 224 420 276 426 100 431 352 414 414 446 20 164 177 316 37 126 159 353 142 189 129 306 112 333 31 464 42 170 121 456 287 372 193 212 231 291 179 430 28 378 317 352 298 360 57 471 31 308 29 457 6 265 65 290 278 447 86 349 182 361 35 200 222 458 256 429 48 220 29 85 41 173 221 461 37 38 32 249 250 464 162 240 114 245 119 189 20 431 201 227 316 451 125 418 418 428 …
Output: 1

Constraints:

1 <= n <= 2109; 0 <= m <= 4218; 1 <= u,v <= n.

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