CT50493

Jatin's Ivory canals

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the savanna camp of Amberplain, Jatin the inventory keeper keeps careful count of the canals. Price the new merchandise line, every figure matters. 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 <= 1687; 0 <= m <= 3374; 1 <= u,v <= n.

Example 1:

Input: 357 1116 100 355 291 345 33 225 81 229 294 298 131 184 251 278 208 225 33 186 100 107 198 346 238 299 122 252 204 274 45 119 74 177 100 119 24 331 29 336 60 220 241 306 175 267 47 282 76 323 13 347 46 140 128 356 15 158 45 241 48 326 39 130 328 356 274 328 134 189 15 151 273 306 257 322 75 310 115 183 312 332 174 226 233 257 41 168 31 326 47 154 61 278 18 143 142 165 303 323 25 266 26 230 2 252 81 237 195 321 170 293 147 294 325 341 189 253 94 178 76 101 144 197 214 327 147 266 216 352 181 297 161 194 17 220 23 75 193 342 167 270 201 292 1 238 31 231 39 351 23 320 59 305 242 356 227 252 42 207 77 94 19 328 317 327 124 126 213 294 89 229 24 55 132 283 76 182 63 181 150 171 45 131 16 103 29 287 138 200 78 335 177 267 95 296 19 51 316 340 226 344 54 103 160 227 4 78 224 331 217 221 116 240 19…
Output: 2

Example 2:

Input: 1446 124 437 614 339 1241 37 1319 160 1118 625 1047 1330 1365 295 718 72 1153 389 762 126 333 102 1136 647 705 644 692 428 1255 1059 1261 97 315 157 1371 570 807 8 53 9 981 86 294 360 671 683 1013 464 1385 546 1036 343 1445 563 1311 118 1225 749 1104 704 1397 57 238 486 1035 1042 1063 5 114 7 1163 491 676 804 831 381 1115 863 1187 386 963 444 1013 335 703 284 1219 184 1398 22 264 172 707 805 1089 551 632 466 551 531 903 445 1244 156 293 671 678 370 1240 149 554 1015 1364 1058 1376 1276 1389 875 1184 794 981 361 785 348 1283 565 1357 530 1415 144 361 761 871 200 1440 500 724 681 910 571 1124 412 1346 1110 1147 900 946 72 739 432 1269 829 1444 739 749 612 1266 669 708 851 888 727 774 324 930 84 1231 429 1332 104 894 954 1024 41 1377 1288 1346 826 994 200 1261 221 1258 374 1075 627 1288 1293 …
Output: 1322

Example 3:

Input: 1276 189 325 752 364 1028 654 859 224 289 369 859 89 126 136 445 468 502 1118 1186 43 744 999 1070 898 1083 456 1085 157 739 228 599 184 1248 273 399 92 987 374 458 900 910 524 818 671 1250 539 685 93 831 392 1116 779 1018 305 1257 957 1195 123 382 353 620 176 917 564 1043 602 1251 287 1036 204 248 135 676 1111 1191 630 1146 880 1101 117 745 373 555 91 860 199 813 208 1220 138 615 269 633 518 571 854 874 368 387 996 1130 48 835 494 607 309 542 313 470 759 838 296 992 475 967 228 527 391 955 154 884 776 863 436 936 452 675 258 1103 922 949 48 544 216 1187 461 893 57 926 309 585 109 875 817 836 439 957 176 382 92 735 821 1213 22 986 573 1275 294 888 497 804 672 1085 92 1078 81 996 155 652 1126 1168 609 636 894 940 455 619 265 556 1121 1275 72 363 197 1205 330 950 704 918 117 469 221 857 626 …
Output: 1087

Constraints:

1 <= n <= 1687; 0 <= m <= 3374; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
Jatin's Ivory canals - MEDIUM Coding Problem | CodeTikki