CT54317

Diya's roads Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the lotus ponds of Tranquil Basin, Diya records each roads 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 <= 3621; 0 <= m <= 3621.

Example 1:

Input: 505 3226 329 16 458 216 220 191 392 496 123 305 214 381 394 457 463 33 50 158 202 488 362 363 231 198 216 67 195 498 114 111 195 132 238 160 77 399 119 457 159 32 363 233 58 167 387 39 444 289 227 4 477 278 108 389 230 298 489 401 35 390 324 97 181 452 7 230 493 3 277 377 315 71 386 246 181 41 436 196 445 327 245 465 200 243 280 155 161 406 52 337 61 227 468 364 476 138 360 390 248 59 324 144 4 105 332 226 411 120 461 84 300 286 366 359 212 250 154 17 262 131 315 237 417 192 160 478 438 107 364 485 361 333 346 182 296 211 232 348 148 402 393 195 358 333 337 454 375 69 8 433 462 44 162 504 493 291 465 58 179 406 114 264 106 419 496 430 125 329 188 96 208 113 495 192 475 236 54 78 121 431 494 383 386 16 336 438 279 364 368 17 252 368 79 69 499 13 139 162 380 105 454 424 375 74 169 482 482 26…
Output: YES

Example 2:

Input: 2539 1836 528 1293 605 1830 1699 297 2457 1957 1972 1959 742 258 1230 2440 1185 1592 1488 676 503 375 1057 86 2010 2398 2517 2539 449 644 961 2126 1843 2314 1369 807 1586 2258 1818 1662 1423 2100 2232 158 331 2133 180 1441 542 1278 2475 2267 1762 567 1924 952 564 1906 1271 603 1803 57 2444 332 1675 149 1670 1773 451 1007 751 152 1910 448 1123 773 282 1088 2177 2210 1038 907 475 33 2279 989 1288 2183 1768 767 1094 732 472 979 2301 1942 1947 397 1066 2329 1341 1560 1770 1504 1610 510 11 1109 1227 853 197 1384 110 2515 1660 2331 292 1221 1151 1340 633 978 2257 1167 1014 2225 152 2359 1754 2327 440 1084 1559 899 2104 2306 1099 1275 2064 1126 2341 639 388 1918 219 1759 1838 815 978 2364 431 262 2251 2518 1505 1695 153 813 998 773 316 1402 664 1071 1993 457 2181 2018 150 2230 2488 989 1744 554 2…
Output: NO

Example 3:

Input: 3531 1763 3080 3096 2336 301 502 2907 1433 192 1652 582 655 176 1730 2361 1391 1458 1522 1764 1333 2705 1648 2201 948 1724 971 1182 1671 1097 684 2154 178 276 2705 719 2668 2002 2813 2531 354 1169 1257 2667 3182 3005 1687 1582 2450 2812 1950 2883 3345 2524 2905 1365 2887 2176 1296 1998 540 1626 3296 2178 899 1581 735 2954 1582 3052 739 1590 3227 94 1178 1030 3065 2738 1678 120 590 2553 1739 2103 2843 314 2570 2266 3505 97 2657 2776 2597 1577 2683 629 841 2810 863 1272 3263 246 2265 2223 1775 3076 405 1466 461 1774 122 1243 1728 1685 570 780 2489 2807 1909 2960 2937 2580 1120 395 737 2592 1381 147 2208 2927 1714 3428 615 3193 1805 1640 661 2966 3019 1335 669 981 2041 1141 1195 2916 2561 3349 2326 1199 1470 3447 2388 1667 3420 1517 2598 1070 2809 3033 1893 716 3501 1899 1781 266 2146 679 207…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Diya's roads Reckoning - MEDIUM Coding Problem | CodeTikki