CT36001

Coral canals Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the ember dunes of Ashfall, someone must plan the festival budget. This year the task falls to Mira, armed only with the canals register. 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 <= 1488; 0 <= m <= 2976; 1 <= u,v <= n.

Example 1:

Input: 718 1272 219 425 336 628 77 714 12 698 193 473 201 203 197 561 98 526 486 534 179 501 94 419 16 601 227 265 379 696 416 651 18 68 139 681 132 503 95 619 76 221 102 636 319 629 117 225 93 498 11 253 386 421 505 673 259 718 151 433 35 413 2 441 103 471 25 40 643 654 393 543 196 297 74 101 187 424 9 578 416 716 465 509 51 99 152 186 391 681 592 710 512 703 137 307 194 573 293 655 232 511 486 669 303 350 294 703 465 717 269 673 296 345 23 152 204 296 211 595 44 697 111 455 417 517 248 518 531 552 63 710 238 555 257 313 545 590 299 478 248 330 186 300 248 344 69 467 407 429 641 718 180 484 166 200 644 684 365 500 159 329 417 452 36 430 100 586 4 545 172 468 324 561 597 689 186 288 350 378 113 664 102 265 411 655 129 704 445 574 279 500 427 662 44 135 149 439 306 394 148 508 61 119 281 340 471 5…
Output: 25

Example 2:

Input: 256 1241 95 209 59 243 11 210 207 256 36 59 67 165 12 17 203 250 24 70 22 64 38 198 90 182 18 133 69 200 101 183 30 68 45 173 15 98 122 165 136 168 38 73 26 240 55 197 12 13 14 88 103 205 24 227 92 137 112 181 204 231 109 179 105 243 9 176 94 246 67 79 42 223 74 234 68 229 31 195 152 193 27 226 20 222 64 211 190 237 175 209 103 249 24 69 48 203 108 162 37 144 55 140 74 231 57 121 172 221 3 130 178 179 69 230 59 73 86 123 62 223 66 89 2 86 178 223 151 182 118 199 71 247 130 200 7 205 76 185 169 236 15 167 135 217 28 134 152 198 39 70 45 227 109 147 104 149 9 183 3 127 13 195 204 218 43 164 19 113 101 113 37 99 46 77 11 125 40 230 122 167 208 249 161 167 24 31 52 178 131 188 101 247 28 79 77 99 60 66 130 141 147 177 70 204 70 251 180 253 42 198 46 227 33 185 21 160 52 105 84 132 133 254 5 11…
Output: 1

Example 3:

Input: 1403 2904 90 432 121 1120 1261 1283 589 1083 1279 1304 124 324 752 1139 515 1022 380 1121 279 1055 1221 1334 346 738 1204 1227 48 1107 521 878 1093 1198 401 1125 679 1386 820 1005 236 456 647 1050 365 672 564 740 365 501 168 1257 91 189 314 770 296 859 92 759 117 329 30 1362 599 1313 175 1260 1373 1380 792 1374 360 574 771 1396 209 1399 226 803 132 1019 398 505 235 548 255 1111 119 330 562 1295 300 888 28 276 953 1335 467 538 509 962 47 907 84 92 369 1252 325 1267 349 597 720 1348 350 1282 49 212 275 1299 649 1027 253 537 801 1220 537 1262 369 374 24 586 383 1052 571 675 472 910 609 1305 304 531 138 655 631 1298 321 518 801 1219 827 1286 851 1219 833 1238 775 916 143 417 175 1324 5 930 70 241 246 826 206 486 1082 1171 177 519 582 1294 13 924 89 581 1293 1303 766 886 514 958 489 658 52 1261…
Output: 24

Constraints:

1 <= n <= 1488; 0 <= m <= 2976; 1 <= u,v <= n.

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