CT29806

The Frosted canals of Vani

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Vani runs the apothecary at the lantern lake of Firefly Mere. Today the books show a list of canals, and the numbers must be worked out before sundown. 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 <= 1727; 0 <= m <= 3454; 1 <= u,v <= n.

Example 1:

Input: 1480 167 307 1133 316 819 452 918 600 665 1323 1459 721 793 440 1098 714 904 213 1242 36 960 915 1310 64 822 811 1083 117 840 542 1472 176 712 819 899 573 706 1203 1265 67 1236 828 921 1094 1122 92 1227 865 934 90 732 102 1383 935 1263 585 1235 315 1460 972 1271 464 655 1303 1370 959 1163 15 556 153 610 263 296 744 1249 603 1023 1007 1255 928 968 290 589 219 221 78 651 630 774 441 1327 1061 1133 566 1343 478 570 1353 1451 701 1049 920 1473 879 1196 631 1415 915 1217 634 1058 159 394 499 1136 417 1428 492 1213 790 1273 433 1066 963 1158 28 645 430 1005 84 248 1066 1239 1321 1459 244 728 715 1471 159 909 709 933 145 829 18 1135 135 1422 141 355 148 1311 737 1252 425 1036 245 400 833 1399 400 487 512 629 240 383 8 352 1419 1474 335 997 280 743 821 1051 1038 1344 65 231 922 1449 732 1467 367 1…
Output: 1313

Example 2:

Input: 1215 1308 101 818 199 322 143 1172 199 1063 128 703 57 409 369 1113 95 574 554 823 154 535 376 648 772 1006 244 392 257 912 1113 1194 515 709 329 952 448 1083 136 604 554 1101 31 439 78 301 729 834 558 596 554 1020 332 1095 422 674 94 1021 376 984 337 1125 163 378 346 529 258 520 227 841 472 702 371 416 410 837 436 1040 1053 1117 203 246 492 1067 556 1103 243 737 554 1130 50 112 127 681 1045 1200 6 573 968 1137 69 1015 183 1127 237 559 484 1028 502 613 307 810 171 1185 292 737 498 945 728 1121 380 555 861 1187 923 1064 237 497 255 1081 40 1015 111 1171 750 940 713 1084 886 1081 431 917 1158 1188 91 987 168 1141 614 638 352 729 223 835 542 996 1028 1071 541 1141 519 737 314 772 200 564 30 966 309 941 148 504 785 1186 18 297 392 1160 510 928 950 1201 811 846 11 173 319 814 1032 1086 56 221 3…
Output: 169

Example 3:

Input: 380 1472 29 200 10 119 92 317 245 280 89 222 137 378 82 155 252 338 257 267 26 151 86 240 332 353 84 314 8 114 32 57 3 16 79 284 241 332 114 209 174 310 23 255 74 246 137 169 111 158 56 124 123 130 185 252 71 313 39 369 105 160 161 203 109 224 56 282 53 281 35 200 103 169 266 369 131 366 138 176 59 261 86 125 165 333 150 180 51 83 255 258 78 101 111 267 258 313 23 213 264 300 2 7 291 317 110 142 115 330 259 292 27 315 31 344 6 64 191 366 213 278 139 193 47 100 98 363 8 139 131 299 29 254 357 372 62 117 73 173 194 223 40 302 183 301 80 120 128 246 61 73 161 195 32 190 8 217 91 342 255 279 1 206 9 259 233 320 87 227 30 183 233 267 255 298 31 254 191 328 232 247 34 281 63 187 167 289 27 278 168 255 261 348 5 40 25 227 201 286 161 341 194 281 151 213 278 359 127 247 6 349 346 368 179 267 1 337…
Output: 1

Constraints:

1 <= n <= 1727; 0 <= m <= 3454; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.