CT33438

The Separate Camps of Vineward

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

In the ivy courts of Vineward, Anaya the auditor keeps careful count of the corridors. Schedule the next expedition, 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 <= 508; 0 <= m <= 1016; 1 <= u,v <= n.

Example 1:

Input: 343 235 148 162 107 200 10 240 25 60 5 94 75 339 103 149 67 248 127 265 66 310 144 206 332 333 254 342 72 168 68 336 247 297 41 160 86 182 70 306 172 211 160 206 157 313 18 332 294 335 26 192 70 186 236 260 227 314 228 234 139 247 212 316 61 136 159 234 90 283 18 173 17 232 157 222 74 235 11 124 156 258 128 152 96 268 35 142 57 96 209 298 11 255 164 256 328 333 26 218 124 146 280 336 39 191 39 196 25 315 76 168 138 311 24 277 146 180 109 317 237 341 182 283 90 258 230 255 210 282 139 334 220 286 250 266 205 255 173 321 308 338 21 23 48 231 55 184 82 229 32 99 2 171 202 290 167 326 5 81 58 99 11 38 152 255 7 295 16 298 83 156 207 227 55 138 111 290 188 301 86 321 5 164 24 242 254 311 79 93 23 128 60 198 64 88 31 305 29 254 220 331 161 340 17 261 142 228 129 215 14 244 1 73 38 166 173 220 18…
Output: 116

Example 2:

Input: 323 813 230 278 9 10 71 74 226 294 209 234 1 269 53 151 109 274 9 171 168 290 123 168 1 260 237 307 245 269 116 251 76 120 56 69 196 253 1 273 10 140 139 273 124 168 307 309 189 243 239 268 110 285 123 193 178 293 143 273 250 313 118 287 2 39 153 296 43 320 100 302 9 306 220 252 110 142 247 248 239 299 54 288 10 276 117 311 161 195 84 282 193 273 9 201 36 216 248 263 183 318 40 289 181 305 85 244 174 242 163 313 96 159 34 266 48 265 12 190 162 183 205 239 40 81 107 240 93 274 10 195 288 289 50 146 145 269 214 243 114 141 19 308 140 289 20 100 171 288 140 147 186 248 211 231 37 48 25 91 20 148 272 297 72 128 97 170 207 268 30 87 157 187 166 239 79 272 6 89 4 278 20 188 46 105 161 287 7 219 55 81 161 267 176 287 89 180 152 163 64 196 62 202 29 58 111 222 1 14 72 210 100 159 68 227 218 228 23…
Output: 3

Example 3:

Input: 119 37 24 26 73 109 3 44 3 8 41 46 85 94 23 113 54 108 19 21 30 56 35 119 50 109 11 105 75 79 12 29 29 52 52 119 34 50 22 80 16 74 33 58 8 43 53 57 31 78 39 118 64 101 24 45 25 80 58 109 7 70 101 117 80 96 7 116 9 67 72 74 4 74 26 71
Output: 82

Constraints:

1 <= n <= 508; 0 <= m <= 1016; 1 <= u,v <= n.

Loading...
Test Cases:No test cases
No test cases available.
The Separate Camps of Vineward - MEDIUM Coding Problem | CodeTikki