CT34322

Devi and the Faded roads

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Legend says the vault under the mangrove channels of Rootwater opens only for a perfect tally of roads. Devi means to find out. 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 <= 594; 0 <= m <= 1188; 1 <= u,v <= n.

Example 1:

Input: 164 564 50 106 14 77 85 99 17 43 63 77 26 99 90 152 33 103 87 141 7 91 133 140 61 162 117 150 15 104 18 67 25 28 62 135 62 77 27 77 20 136 1 148 33 88 85 162 26 73 57 102 15 26 6 49 44 123 147 151 102 138 59 149 21 69 17 67 72 90 35 71 49 76 18 112 41 146 95 119 19 97 54 128 77 135 68 81 120 146 27 106 16 97 28 29 39 160 47 134 37 138 56 135 137 161 12 32 25 41 83 88 27 153 12 33 13 15 65 162 96 129 43 45 32 51 105 114 6 162 29 163 89 148 114 118 50 105 35 121 144 147 140 151 37 104 44 112 103 114 85 144 50 121 29 144 46 120 101 132 46 55 2 122 70 73 2 29 32 119 107 127 51 109 62 70 40 131 60 71 17 116 14 29 60 87 31 76 19 60 74 164 59 108 62 68 20 86 107 159 70 101 88 89 61 106 146 156 94 161 83 153 74 149 19 111 22 154 25 88 4 59 86 151 132 152 151 163 27 63 84 150 10 59 36 120 29 130 11…
Output: 1

Example 2:

Input: 468 16 111 439 192 226 16 193 122 457 350 378 109 355 240 403 91 129 43 237 109 285 196 249 106 164 333 451 208 378 235 346 84 388
Output: 452

Example 3:

Input: 302 321 179 198 167 290 194 276 35 87 160 214 249 256 79 202 280 294 60 257 243 281 195 227 198 259 88 301 23 267 11 89 112 245 44 302 64 296 32 153 180 285 16 206 155 172 75 188 253 285 257 297 10 207 213 290 16 177 247 277 62 238 132 268 42 288 10 276 205 240 199 235 100 153 78 197 27 295 110 232 64 103 3 276 108 241 42 164 12 61 167 247 11 187 86 121 31 35 30 183 89 115 3 255 34 116 10 110 220 253 44 238 98 122 68 121 186 187 91 216 154 265 160 190 101 150 114 290 137 260 97 213 129 176 162 171 143 259 102 193 225 298 54 256 173 300 51 214 191 302 18 136 99 296 51 236 42 140 181 214 77 195 169 283 48 265 88 239 37 224 48 165 125 275 52 246 213 274 3 180 14 28 78 224 89 298 106 281 12 124 150 212 18 146 76 160 82 132 209 223 80 123 241 253 40 262 68 236 141 153 72 135 191 247 102 209 137…
Output: 43

Constraints:

1 <= n <= 594; 0 <= m <= 1188; 1 <= u,v <= n.

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