CT46877

Eklavya's corridors Separate Camps

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Eklavya inherited the apothecary at the opal reefs of Shimmerdeep along with its curious bookkeeping system for corridors. Time to make sense of it. 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 <= 1645; 0 <= m <= 3290; 1 <= u,v <= n.

Example 1:

Input: 1194 2534 180 1028 857 942 1026 1129 622 853 49 402 205 1040 18 326 45 1016 610 1075 299 954 536 887 248 549 438 654 70 263 435 790 16 569 214 704 659 910 763 1152 65 985 483 873 548 1176 716 975 172 522 717 889 716 952 912 1182 493 1017 311 639 76 1093 887 1017 539 1116 94 234 374 1165 221 1026 1127 1128 712 1019 676 1054 128 936 1 592 912 924 23 568 46 974 721 1096 783 1026 4 1034 1007 1188 1133 1176 259 453 431 907 21 834 854 1174 236 291 278 869 973 1113 646 1115 683 1045 159 1134 294 749 926 1027 52 982 395 1114 732 951 107 384 778 1068 364 630 437 575 92 1192 187 285 142 416 823 909 97 617 555 1113 75 797 457 687 1026 1180 978 1065 731 759 303 816 329 867 345 406 313 680 123 1184 598 653 653 712 157 385 2 735 659 758 847 1039 67 891 477 1169 302 777 776 946 148 1180 196 316 271 791 3…
Output: 20

Example 2:

Input: 577 141 191 559 154 262 464 472 403 515 255 361 139 391 35 92 165 384 237 245 183 343 376 480 22 373 201 253 245 450 321 342 103 451 92 433 135 527 26 124 213 487 28 207 400 521 97 527 91 296 23 530 271 545 245 360 194 216 82 428 111 481 306 495 84 278 119 377 5 7 220 465 293 561 519 572 135 454 40 322 50 365 224 374 387 528 20 115 271 505 26 143 201 242 239 563 190 353 317 563 142 569 160 353 138 242 392 446 160 307 491 544 224 467 72 279 334 346 125 208 134 315 151 330 450 498 92 218 163 509 222 554 32 364 173 192 195 530 247 264 171 172 204 360 128 205 55 362 123 305 250 301 69 291 351 518 349 359 229 449 111 183 145 171 139 299 359 534 199 266 171 531 204 576 192 289 149 343 2 255 122 355 73 241 210 394 45 146 278 413 227 487 208 327 21 293 339 502 171 391 25 347 126 269 35 498 309 544…
Output: 436

Example 3:

Input: 117 2399 80 106 12 34 77 86 5 115 34 66 52 75 85 87 55 70 29 71 22 103 41 89 9 30 8 33 22 86 68 109 46 103 17 98 30 53 97 110 31 78 1 35 34 47 85 98 12 116 51 82 13 99 6 104 40 81 34 54 34 89 21 60 59 96 62 94 10 75 92 110 4 66 61 70 43 87 45 103 37 97 32 111 12 107 7 11 24 99 18 24 107 112 10 116 23 53 11 104 92 105 16 75 10 49 25 50 38 49 64 86 42 43 110 116 2 53 5 29 3 100 41 78 31 32 41 116 86 97 27 84 39 87 75 83 13 95 15 26 67 98 25 100 91 92 14 75 33 117 23 56 100 115 71 76 10 40 45 107 74 88 32 36 55 80 1 56 31 84 68 102 85 114 43 94 97 103 88 97 72 85 14 37 8 24 31 117 39 51 5 13 10 61 11 25 42 106 31 101 33 106 57 105 76 98 30 94 17 104 52 92 36 60 47 97 8 25 16 114 55 114 5 70 65 83 39 94 51 60 5 15 17 27 53 74 46 57 71 97 65 115 3 27 30 102 21 57 67 87 65 92 1 42 3 62 49 105 61…
Output: 1

Constraints:

1 <= n <= 1645; 0 <= m <= 3290; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Eklavya's corridors Separate Camps - MEDIUM Coding Problem | CodeTikki