CT54828

Wheelwright and the Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the honey farms of Buzzwell opens only for a perfect tally of routes. Wheelwright means to find out. 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 <= 2276; 0 <= m <= 2276.

Example 1:

Input: 451 1031 348 83 190 20 99 200 181 37 138 221 273 109 389 290 131 163 212 150 427 344 16 91 395 292 215 152 259 405 345 97 331 307 180 371 265 376 165 211 78 57 395 82 304 37 420 444 338 375 449 82 222 49 400 27 63 245 375 95 444 265 68 206 353 117 396 210 347 162 248 22 79 30 115 157 288 81 41 306 286 361 247 224 190 355 31 67 87 128 399 247 205 271 284 391 212 222 212 142 119 89 170 228 265 65 410 258 210 15 52 151 138 399 351 79 133 29 261 298 302 100 191 6 357 51 328 337 370 195 432 414 284 110 274 327 175 42 237 59 138 189 98 43 309 163 305 350 377 176 233 324 34 98 80 404 181 325 215 104 110 182 59 387 237 19 398 314 384 338 160 353 382 427 326 417 165 210 307 148 270 48 299 239 8 64 401 43 164 407 41 230 95 169 330 183 151 105 446 283 98 398 244 110 96 442 167 52 44 185 17 192 294 11…
Output: YES

Example 2:

Input: 285 13 103 223 59 67 193 151 26 58 5 185 9 50 199 44 149 92 207 47 253 182 190 274 229 211 193 167
Output: NO

Example 3:

Input: 1358 2213 878 622 760 967 750 165 598 734 36 670 896 284 1117 574 526 1210 433 445 145 818 238 508 432 510 666 906 903 1190 1273 531 259 1234 102 1202 1072 1109 640 139 347 694 17 1214 331 53 1076 636 1207 1335 295 904 1343 473 42 419 1107 236 429 722 1076 88 1163 1284 531 392 117 378 692 1064 180 1122 467 1292 577 278 1276 447 153 380 178 54 293 722 897 637 163 796 1281 250 1167 592 954 146 639 709 426 744 474 1316 1250 289 1116 653 759 975 699 890 884 677 724 918 717 341 671 715 716 1091 232 127 146 757 661 1087 1030 844 885 494 808 121 1272 493 915 1314 828 834 1154 553 1138 441 88 1173 542 1346 1214 389 288 202 818 1174 1219 639 1238 232 686 560 936 1093 1209 481 95 16 393 565 1148 537 139 377 282 888 1064 1031 1015 762 1355 208 882 638 80 595 462 49 721 214 646 330 752 1049 290 691 31…
Output: YES

Constraints:

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

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