CT52279

Galen's canals Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the foggy moor of Greyfen, Galen records each canals in a worn leather ledger. The guild wants answers, not guesses. Task: Print YES if the directed graph contains a cycle, otherwise NO. Input format: First line: n and m. Next m lines: u v (directed). Output format: Print YES or NO. Constraints: 1 <= n <= 2282; 0 <= m <= 2282.

Example 1:

Input: 1177 1642 1083 1130 233 1055 246 909 466 494 592 76 461 1098 356 1021 840 170 100 143 238 331 221 181 148 10 1155 703 1141 1099 761 167 329 594 477 493 1059 255 757 482 140 667 1036 648 119 318 1173 837 156 140 1164 1016 1010 434 852 245 1141 367 1072 899 509 14 432 224 104 1088 548 992 117 1172 1109 1132 1093 578 933 987 658 1158 252 448 937 826 792 1033 1132 436 1162 1112 1096 2 75 414 597 655 772 1107 226 441 59 206 1133 507 196 513 117 4 43 272 181 698 784 270 598 976 819 190 664 422 1059 497 861 160 1012 345 610 149 170 437 156 948 142 520 705 829 866 1077 1124 777 968 1018 992 925 1165 597 1157 114 494 604 535 91 756 345 160 1173 585 758 653 39 106 800 544 173 318 862 178 677 120 446 155 289 1025 250 33 234 239 804 1155 1055 1014 1088 220 596 697 878 450 801 848 540 550 38 99 824 856…
Output: YES

Example 2:

Input: 323 457 305 190 208 22 66 176 273 94 200 209 64 321 166 195 165 95 117 10 135 144 80 312 269 271 292 123 122 302 288 157 88 235 105 185 239 130 193 206 274 179 230 319 167 287 164 218 234 178 14 303 259 61 185 180 108 312 131 43 49 128 125 148 233 151 295 75 38 6 293 33 3 312 160 40 306 278 240 278 58 201 49 62 159 317 218 82 82 204 46 23 162 46 39 29 244 198 153 33 108 168 139 44 118 150 26 61 66 170 297 24 245 174 113 90 170 154 306 54 286 73 43 139 237 136 210 74 221 276 51 272 299 54 146 198 189 164 82 305 170 322 123 219 160 252 288 299 90 152 215 187 269 291 43 36 36 22 28 52 48 145 72 224 118 270 305 290 78 49 162 132 267 311 56 4 8 246 104 214 141 218 184 211 228 269 293 80 320 135 54 14 72 189 81 225 42 52 19 199 267 53 244 228 235 194 45 20 81 166 256 53 265 253 105 192 54 160 97…
Output: YES

Example 3:

Input: 349 1130 340 56 202 131 300 79 200 21 137 281 81 167 175 35 249 27 318 48 219 179 154 95 253 86 344 162 45 194 136 327 207 140 272 343 264 83 186 28 166 16 56 320 101 187 239 89 163 289 77 301 218 30 315 214 282 68 275 103 262 136 120 216 190 169 189 24 93 87 120 115 37 129 171 100 222 211 51 183 261 329 161 250 255 262 92 217 13 19 98 68 273 65 42 13 2 323 306 320 56 166 313 307 14 309 139 285 257 219 125 269 180 223 53 93 32 62 190 105 256 156 344 3 2 228 183 64 218 258 189 152 288 110 93 51 25 343 334 34 16 322 184 41 232 148 73 140 65 197 103 18 40 23 53 51 142 222 211 127 22 90 223 196 230 169 195 241 348 134 233 247 70 302 40 70 222 180 236 133 267 289 300 5 309 201 314 123 295 335 213 261 124 214 51 58 94 320 234 148 212 156 89 41 273 205 13 245 15 4 245 9 211 5 7 150 158 283 244 29…
Output: YES

Constraints:

1 <= n <= 2282; 0 <= m <= 2282.

Loading...
Test Cases:No test cases
No test cases available.
Galen's canals Circular Route - MEDIUM Coding Problem | CodeTikki