CT44947

The Stonehallow Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Rohan runs the chandlery at the granite steps of Stonehallow. Today the books show a list of canals, and the numbers must be worked out before sundown. 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 <= 1938; 0 <= m <= 1938.

Example 1:

Input: 1090 939 708 109 508 220 430 1021 211 536 597 870 625 444 788 988 414 418 536 827 1074 894 549 586 238 857 453 508 281 779 231 665 53 477 1031 220 860 589 184 489 289 294 149 176 332 861 880 305 452 778 846 499 1004 766 106 671 181 538 175 689 1066 1020 3 285 153 769 695 421 418 731 843 730 124 535 922 806 509 864 301 525 1083 135 663 442 891 414 561 179 738 396 955 632 942 443 661 189 1010 202 90 218 357 816 934 819 219 735 345 931 436 104 202 908 825 60 604 518 669 603 961 32 896 683 278 261 741 617 346 297 446 762 524 1036 1021 397 212 975 268 576 367 1059 106 1024 829 888 461 678 875 890 1008 323 1054 236 641 367 408 1005 671 64 55 1090 995 614 253 130 117 401 263 268 237 197 469 50 143 922 129 908 896 768 282 481 992 1050 1036 433 940 600 789 278 305 486 756 304 1005 769 918 916 100 6…
Output: YES

Example 2:

Input: 21 90 17 5 9 15 11 10 2 17 19 14 3 4 15 1 17 18 2 6 5 1 17 21 7 20 9 12 8 18 20 21 19 4 14 21 1 18 15 19 12 5 11 4 7 18 15 3 4 15 19 8 14 19 8 9 4 19 19 10 14 18 12 6 20 4 6 17 4 18 6 2 18 3 9 13 19 13 13 11 17 13 11 9 1 9 17 4 16 20 19 16 18 8 20 11 3 5 13 17 5 16 14 13 13 14 17 19 9 3 5 13 3 20 21 8 5 11 3 9 13 21 19 15 21 19 5 12 20 19 12 14 3 14 6 19 15 8 4 3 11 15 20 5 1 7 5 2 16 11 16 15 3 2 5 10 9 14 7 16 10 7 13 8 5 17 7 4 15 14 19 2 6 13 18 12 16 14 2 15 17 8
Output: YES

Example 3:

Input: 460 1342 365 83 330 307 149 346 342 364 192 206 265 303 411 414 320 335 257 106 322 169 22 302 267 48 103 375 54 317 138 343 398 128 369 175 91 69 354 35 279 440 163 452 181 289 431 345 290 53 171 409 186 357 364 96 186 89 73 273 88 245 408 228 92 245 124 40 85 115 205 342 88 127 251 8 85 335 29 1 254 65 63 431 113 228 416 376 357 277 155 31 324 391 251 140 14 160 6 268 412 203 272 377 1 208 459 282 310 276 22 176 437 12 41 267 210 342 120 261 298 403 122 186 201 265 278 223 315 230 312 419 145 406 257 71 449 79 186 341 30 342 302 39 57 133 432 443 17 31 190 81 168 333 357 54 240 104 259 182 314 199 157 69 215 265 163 352 103 184 337 26 91 174 265 382 275 165 8 390 176 404 154 454 215 154 199 327 158 75 341 172 196 240 386 114 87 225 118 25 128 334 355 27 98 454 245 432 198 424 97 128 322 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Stonehallow Circular Route - MEDIUM Coding Problem | CodeTikki