CT45346

Bhanu's Ledger of bridges

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the river town of Willowford with crates of bridges, and Bhanu the archivist must account for every last one. 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 <= 1260; 0 <= m <= 2520; 1 <= u,v <= n.

Example 1:

Input: 304 1184 244 304 64 135 93 233 17 230 115 193 7 147 85 226 6 199 83 276 112 184 105 117 53 265 136 190 244 298 1 225 211 245 199 259 29 94 145 152 39 150 68 235 52 297 131 152 47 296 69 185 204 271 19 52 248 295 73 142 187 281 104 237 59 146 192 248 184 196 53 292 189 237 63 287 90 221 22 207 269 277 72 163 119 166 111 121 204 235 32 202 282 295 23 207 41 272 122 164 47 178 26 245 10 18 28 181 22 209 109 128 4 121 100 239 73 99 187 195 158 210 89 193 52 207 66 141 188 262 49 243 46 110 165 231 13 99 172 243 22 279 31 263 50 108 264 297 115 259 30 55 18 114 18 239 196 209 31 145 149 266 220 279 52 300 145 169 1 186 4 293 10 157 205 210 2 74 116 208 48 216 254 303 145 167 12 168 264 274 10 93 248 250 21 200 130 227 41 96 97 204 44 200 1 252 205 232 67 88 72 297 115 241 17 273 50 157 85 218 9…
Output: 1

Example 2:

Input: 347 1502 83 158 227 235 136 303 39 249 282 296 35 65 115 345 71 334 256 326 288 340 61 137 101 299 28 205 80 273 136 155 136 327 159 164 31 46 170 255 24 268 124 129 317 343 131 331 31 144 65 131 122 264 66 103 261 338 12 300 28 343 145 257 128 274 172 328 330 341 160 270 38 169 111 212 144 176 190 232 13 183 20 114 36 285 107 153 83 317 11 184 9 347 112 257 264 302 189 209 15 222 26 291 119 166 77 323 161 181 137 238 226 330 74 274 1 59 116 122 134 187 221 228 273 299 172 338 169 173 53 322 287 336 272 340 225 300 36 126 45 73 198 227 206 257 146 149 19 130 72 98 306 316 4 328 79 267 190 255 56 187 141 260 103 305 210 222 89 162 27 40 285 327 61 118 205 220 50 122 152 160 7 312 82 173 311 314 55 104 74 176 142 213 178 186 85 326 61 139 53 240 178 219 293 294 102 334 68 243 20 243 83 306 1…
Output: 1

Example 3:

Input: 931 1252 223 354 81 500 160 708 341 636 189 922 350 880 875 879 112 611 324 506 173 217 191 737 157 693 150 200 501 928 474 547 4 892 352 902 690 754 20 592 437 765 424 629 128 761 599 732 347 557 618 807 787 895 194 577 113 339 463 466 695 892 282 751 241 487 114 891 153 700 142 432 160 704 142 775 57 126 90 755 175 595 448 589 473 522 23 473 349 804 106 547 384 415 231 354 369 821 35 259 24 871 731 798 865 919 550 704 16 285 165 735 702 856 466 909 280 467 704 732 373 897 643 691 103 889 10 654 24 703 567 762 42 850 400 894 520 698 447 853 674 814 39 45 194 403 626 675 557 875 142 453 268 775 241 745 76 701 315 413 345 482 576 755 357 424 46 191 587 905 72 269 251 521 97 853 665 809 114 656 56 871 232 268 580 847 109 824 757 832 21 506 836 844 272 442 325 407 565 576 37 857 157 264 168 2…
Output: 79

Constraints:

1 <= n <= 1260; 0 <= m <= 2520; 1 <= u,v <= n.

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