CT31147

Ivo's Peculiar tunnels

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the tannery row of Leatherwick. Ivo spreads the tunnels records across the table and picks up a sharp pencil. 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 <= 1747; 0 <= m <= 3494; 1 <= u,v <= n.

Example 1:

Input: 1285 1535 311 1091 32 895 85 1084 987 1235 703 982 88 1271 138 356 706 1187 27 264 71 179 750 1186 291 1049 685 1022 117 1124 243 798 404 580 469 510 232 903 894 1039 946 1161 459 801 116 897 419 555 823 1167 159 565 307 1059 803 1252 1012 1285 122 1043 999 1203 323 538 500 1213 561 1271 950 1115 1038 1096 1008 1023 679 715 277 287 683 1004 1125 1257 109 842 218 1021 986 1044 294 898 183 507 448 1107 796 870 544 871 295 503 228 402 427 562 245 368 233 985 117 1001 19 1233 107 1142 223 274 172 1007 615 810 481 941 1058 1256 201 1207 2 1219 477 1199 430 1259 238 1046 349 958 791 913 3 1022 72 744 351 754 200 711 223 636 226 1056 457 1081 834 1216 387 470 44 1168 175 834 417 1117 426 1154 198 1070 275 532 55 908 444 1131 505 854 758 911 288 582 98 281 1072 1225 517 984 399 867 29 1108 388 121…
Output: 132

Example 2:

Input: 710 2197 34 390 340 516 347 615 29 581 55 189 114 380 242 423 246 393 93 659 470 493 443 552 145 614 185 685 86 703 110 288 258 451 17 577 429 572 192 710 114 426 133 482 411 648 231 652 15 438 251 466 392 697 92 456 559 578 164 276 258 709 617 620 22 488 541 614 340 476 142 230 592 648 450 487 148 668 550 674 615 675 385 671 225 708 195 444 497 526 126 707 79 275 521 570 224 514 97 374 513 567 7 508 69 676 151 377 274 650 462 546 129 530 564 581 370 668 302 668 41 521 319 494 316 501 151 524 321 692 102 308 32 285 86 383 270 401 446 568 287 288 111 708 272 456 25 463 173 698 77 89 457 668 674 681 467 588 68 281 494 528 371 669 389 592 253 699 226 660 538 693 53 89 62 335 150 479 145 693 142 621 258 407 38 324 260 309 399 627 403 587 44 118 14 526 406 702 183 668 24 565 63 582 87 139 14 45…
Output: 5

Example 3:

Input: 315 2188 65 274 235 276 106 240 30 149 81 244 109 113 23 61 72 80 136 308 8 53 60 166 102 132 16 96 78 113 12 167 21 69 67 184 34 242 174 296 67 170 87 148 60 102 89 200 49 125 90 234 85 92 1 174 84 282 34 273 26 75 48 220 187 253 116 282 158 246 4 258 25 247 99 171 144 291 74 136 33 193 295 307 162 225 67 160 35 116 40 261 61 272 276 308 168 219 84 290 10 252 80 215 264 310 35 243 89 243 182 251 11 296 84 213 89 214 31 153 12 201 225 311 187 306 220 296 22 75 104 175 120 223 153 172 7 56 70 92 143 300 49 309 131 253 142 210 195 201 18 200 78 253 13 174 71 309 141 267 27 58 82 280 116 265 26 311 11 305 46 248 113 292 191 225 8 20 181 285 300 313 4 306 190 288 58 308 132 226 225 285 47 307 105 252 36 41 36 263 97 198 66 227 82 297 14 34 39 62 110 230 70 85 59 110 163 175 121 242 115 143 35 …
Output: 1

Constraints:

1 <= n <= 1747; 0 <= m <= 3494; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Ivo's Peculiar tunnels - MEDIUM Coding Problem | CodeTikki