CT34962

Keeper's Crystal canals

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Deep in the forest village of Briarthorn, Keeper studies rows of canals entries. One clean number will settle the guild's oldest argument. 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 <= 1754; 0 <= m <= 3508; 1 <= u,v <= n.

Example 1:

Input: 1626 537 120 1624 21 991 243 469 856 1392 44 1410 406 940 882 1062 605 1378 384 1247 313 1608 323 1545 424 1150 1215 1564 273 744 200 1213 189 1422 952 1314 730 1265 1232 1429 105 1439 326 352 561 1204 398 465 1105 1391 1394 1480 372 1313 516 1243 127 659 792 986 111 424 372 1188 71 352 126 339 273 1097 252 1029 85 1300 128 1403 95 1411 401 906 822 1372 469 588 591 1346 821 962 759 896 281 1454 288 629 53 1420 386 1049 10 1476 601 1339 935 1059 102 1162 236 1086 5 743 375 421 967 1200 94 1455 363 1232 124 587 397 1519 326 1540 920 1487 112 747 1415 1516 392 1055 188 1253 342 1008 486 1200 123 290 967 1233 1096 1493 104 331 679 1253 1391 1478 890 1031 1173 1319 1091 1323 1320 1455 657 917 268 1103 951 1196 2 1302 338 1494 45 1307 156 1392 517 802 1263 1397 343 1088 163 796 294 1065 80 1416 …
Output: 1089

Example 2:

Input: 99 1645 10 51 56 96 31 95 2 46 1 84 41 58 28 55 81 85 51 68 3 44 13 57 20 54 50 62 69 91 29 39 69 82 53 82 43 69 23 79 42 86 26 76 34 49 28 66 24 92 20 75 2 13 16 91 83 99 21 48 27 78 51 93 46 92 35 74 31 81 33 50 77 88 41 62 25 55 2 14 65 92 1 54 29 95 26 63 9 89 38 83 17 90 14 84 10 91 18 89 14 34 19 30 1 4 66 79 9 60 13 78 8 21 14 90 5 91 7 93 25 37 19 27 34 67 40 59 1 66 71 92 16 69 61 67 27 39 2 37 28 79 45 61 12 32 34 77 6 99 51 70 86 99 31 76 6 90 34 66 43 64 29 96 32 47 33 40 40 57 36 90 64 92 57 71 20 38 11 17 25 83 3 48 42 78 9 16 20 40 33 79 42 76 15 58 23 29 27 63 81 93 18 91 61 89 30 75 22 94 21 67 71 79 62 98 2 84 73 74 2 64 5 71 16 61 19 34 37 82 54 87 49 55 38 75 77 89 54 92 74 96 10 26 38 87 12 57 20 86 29 89 15 73 22 74 7 37 12 24 27 29 1 22 42 47 62 86 25 26 67 85 3 11 2…
Output: 1

Example 3:

Input: 1571 2192 69 705 474 614 46 510 199 758 525 736 253 1362 31 1222 254 1194 285 1204 526 1295 1199 1549 373 888 1244 1519 469 698 287 1551 108 243 1270 1307 840 1007 380 1058 268 1306 590 1383 411 1133 814 1003 924 1146 1492 1557 859 1570 161 811 448 1099 154 1476 182 705 836 1495 21 625 868 884 231 588 298 447 777 802 651 1045 709 1008 1317 1372 103 1302 201 1438 720 909 108 577 830 1348 59 671 1001 1414 789 1330 235 470 137 139 919 1453 422 701 1071 1078 752 1055 456 1232 751 994 483 1123 410 1237 916 1239 885 1133 180 1172 183 1200 93 1136 455 482 13 204 883 1061 407 1153 1 537 56 1235 67 1178 1110 1410 1212 1358 1380 1447 5 1181 1094 1468 205 420 241 739 1183 1482 131 347 212 972 41 773 949 1159 330 682 959 1373 869 1097 532 708 367 1192 448 1034 430 1222 845 1396 1126 1146 614 1074 946 …
Output: 114

Constraints:

1 <= n <= 1754; 0 <= m <= 3508; 1 <= u,v <= n.

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