CT31425

Jaya's Ledger of tunnels

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The harbor bell rings at the cork grove of Barkhaven; Jaya weighs the day's tunnels manifests and starts the calculations. 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 <= 914; 0 <= m <= 1828; 1 <= u,v <= n.

Example 1:

Input: 182 87 148 172 123 131 76 174 87 142 66 122 52 74 98 161 18 48 3 157 76 172 162 172 71 82 55 128 87 110 10 55 83 135 103 117 118 128 113 141 158 161 51 62 119 156 49 120 84 174 41 106 28 76 78 168 87 172 32 58 5 104 9 64 85 131 39 128 74 112 81 122 135 173 47 102 58 62 9 72 40 84 31 102 111 165 92 119 32 174 73 82 39 71 3 73 84 90 68 127 37 112 68 72 1 128 1 141 79 118 145 147 148 151 43 163 152 163 87 89 149 173 82 90 110 114 164 167 99 171 37 56 75 131 29 179 133 168 114 179 107 117 57 84 75 100 80 172 37 59 27 122 123 170 3 163 2 101 168 175 64 150 21 114 8 164 144 160 21 167 7 168 53 142 15 27
Output: 95

Example 2:

Input: 304 1254 39 131 52 183 265 273 9 273 204 228 148 196 19 36 58 177 162 166 176 211 21 78 168 283 13 70 22 113 122 291 74 101 106 161 214 220 204 294 99 105 90 285 29 285 7 221 14 109 253 276 151 224 41 65 6 277 24 54 48 188 164 287 123 194 73 164 1 203 58 195 74 231 36 147 22 110 118 280 239 284 55 155 91 144 27 191 177 189 152 195 260 297 82 84 21 101 33 168 192 264 29 114 122 186 91 132 19 63 131 162 26 63 206 259 66 281 46 122 162 233 19 302 190 200 4 131 15 276 33 220 78 185 35 253 8 178 79 106 58 184 106 113 8 146 145 166 19 300 226 249 22 109 38 142 179 196 58 74 216 260 2 10 50 93 16 164 47 137 53 86 90 283 179 256 14 124 193 226 44 143 21 37 209 245 80 111 25 29 22 53 179 285 226 281 162 202 21 242 101 157 229 275 192 275 60 250 62 90 61 105 40 247 152 223 9 296 120 136 152 162 242 …
Output: 1

Example 3:

Input: 662 1395 228 360 380 398 301 522 152 248 135 385 287 482 616 645 12 631 169 554 346 450 428 588 136 241 127 168 91 512 285 451 174 649 20 380 83 256 482 581 249 522 192 444 99 323 456 621 99 120 402 566 503 616 398 657 463 518 363 535 91 290 124 464 62 381 356 491 207 632 44 349 515 636 370 552 186 594 238 592 176 235 581 594 185 515 60 460 146 293 309 594 459 628 14 635 365 557 341 654 221 555 73 632 184 454 465 607 506 632 250 539 251 404 190 347 229 293 91 436 67 282 163 180 228 637 75 553 110 567 51 548 285 351 199 654 522 566 46 156 210 628 4 116 227 440 206 277 37 377 432 547 3 81 168 323 4 555 49 563 59 74 96 393 94 586 20 556 108 132 138 528 183 658 172 525 446 586 28 648 431 571 29 257 156 558 114 279 425 521 166 497 384 567 54 608 372 381 393 497 3 414 559 645 175 548 430 483 312…
Output: 12

Constraints:

1 <= n <= 914; 0 <= m <= 1828; 1 <= u,v <= n.

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