CT31186

The Moonlit tunnels of Urmila

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The harbor bell rings at the northern keep of Frostgate; Urmila weighs the day's tunnels manifests and starts the calculations. 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 <= 868; 0 <= m <= 1736; 1 <= u,v <= n.

Example 1:

Input: 216 460 7 120 22 191 109 183 136 202 119 168 52 141 4 12 128 129 79 129 17 119 34 199 102 148 153 179 81 112 61 102 51 100 10 141 41 131 114 171 37 178 45 105 159 179 20 208 94 202 92 206 81 127 64 99 65 175 63 95 3 62 109 124 102 194 58 128 142 156 97 180 86 102 86 184 14 90 153 154 10 16 126 140 188 215 95 132 150 172 49 80 18 120 165 188 59 204 91 181 40 97 77 178 72 212 180 205 1 109 80 108 29 119 74 142 37 122 92 215 131 142 151 169 114 199 120 188 87 98 19 51 38 167 44 60 101 182 36 188 97 193 54 116 54 142 58 176 56 174 8 175 135 162 38 182 53 184 45 90 123 200 112 158 25 138 21 29 22 211 155 203 85 86 152 185 16 19 33 52 21 181 136 179 9 146 114 209 48 76 160 172 45 58 17 58 46 113 63 66 155 195 76 172 95 155 10 195 37 173 12 55 90 112 17 108 45 206 25 137 139 168 34 175 30 71 88 2…
Output: 5

Example 2:

Input: 527 66 244 508 435 441 273 481 244 485 54 142 348 412 85 519 275 415 13 520 212 235 68 512 305 459 267 401 201 340 153 381 32 454 171 516 3 171 216 225 145 299 391 423 111 295 49 471 278 439 263 320 187 356 30 122 73 169 20 110 223 352 495 501 268 431 63 419 381 509 186 231 195 200 458 504 232 409 378 489 346 355 15 149 99 525 297 311 74 256 433 502 58 248 234 332 484 497 222 313 120 526 253 504 9 471 333 334 221 376 177 483 281 329 174 368 118 366 254 516 50 243 152 488 92 124 190 433 94 452 221 489 327 403
Output: 461

Example 3:

Input: 184 1478 75 117 99 184 163 164 38 175 74 152 19 105 114 151 128 144 5 155 50 112 25 181 56 90 73 149 84 100 105 129 126 142 32 144 30 164 12 100 21 157 120 122 154 181 142 180 71 111 26 74 112 173 40 165 15 154 122 177 28 34 163 166 112 150 102 157 62 137 26 30 11 109 140 174 53 108 10 150 11 59 39 68 108 122 94 147 43 114 54 74 10 29 64 134 84 138 86 167 110 172 7 69 28 38 37 86 16 76 116 158 14 134 32 85 124 166 104 131 59 158 48 160 69 86 116 134 115 145 62 81 87 139 46 65 11 93 65 128 13 23 27 46 39 72 170 180 41 183 79 100 18 138 72 95 143 158 75 89 36 48 41 135 22 81 11 148 59 90 8 73 77 147 1 7 58 117 53 115 155 172 58 169 87 104 72 121 29 83 45 140 86 136 25 172 53 118 19 27 38 116 95 131 92 104 34 50 82 112 95 170 75 174 135 168 62 118 55 172 110 149 61 87 34 114 57 181 51 117 87 …
Output: 1

Constraints:

1 <= n <= 868; 0 <= m <= 1736; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Moonlit tunnels of Urmila - MEDIUM Coding Problem | CodeTikki