CT51890

The Circular Route of the Garnet roads

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Grey inherited the gallery at the ink district of Scriptoria along with its curious bookkeeping system for roads. Time to make sense of it. 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 <= 2322; 0 <= m <= 2322.

Example 1:

Input: 1260 2228 370 569 256 109 693 711 425 332 401 880 630 394 555 564 773 944 981 148 1029 1136 609 216 698 1094 1179 790 492 632 26 701 1082 1149 93 409 352 1142 148 556 442 1169 626 176 806 158 582 509 8 2 1089 826 1004 281 968 691 760 473 579 380 1245 526 721 186 90 820 107 875 523 448 433 493 829 427 830 124 138 1036 308 904 663 1253 405 416 986 869 447 329 363 760 935 386 264 946 844 988 991 408 397 282 502 631 481 1031 744 1222 566 368 441 4 530 658 813 346 783 1049 944 423 280 112 963 51 347 413 899 129 168 283 419 296 217 960 246 1231 150 1250 90 513 647 1110 1244 170 3 965 97 797 418 1127 395 228 1238 496 1239 538 351 307 147 372 920 320 1076 938 1236 547 427 1057 46 233 265 212 803 871 93 1246 227 116 796 60 231 534 806 294 326 1232 699 216 1014 291 671 298 705 102 980 234 1043 985 1…
Output: YES

Example 2:

Input: 2136 2026 211 291 1656 649 713 174 2052 336 1456 732 826 851 830 884 415 1058 222 705 1858 1973 226 1910 1656 1848 1513 1476 1754 870 1197 1647 1750 1530 1854 1757 518 56 2122 1355 1078 1337 1266 1409 1412 491 1874 650 501 1371 2089 299 970 569 541 1334 517 1255 596 1674 932 1371 1416 1985 180 800 1657 377 1725 1327 1221 158 190 2116 1268 694 1274 2135 1999 1941 2102 1846 1248 32 1305 2007 1004 262 1945 1413 894 1287 279 1825 541 842 590 905 534 419 1162 218 1502 758 1104 1680 1998 1353 1812 655 275 1211 1653 901 127 833 752 1944 2127 1333 2050 2106 1429 1422 14 1957 1839 1780 1641 763 687 824 2090 333 1083 1477 405 1619 225 1051 355 472 1148 765 1670 1480 314 1455 34 613 1885 778 1270 1751 1290 831 2044 2001 2027 514 358 2006 1469 1806 1261 464 1046 1223 2022 1158 1128 772 1714 155 776 13…
Output: NO

Example 3:

Input: 1502 864 840 643 183 1012 1080 594 119 929 976 86 534 1438 1273 254 125 1195 791 254 996 1403 166 678 907 953 623 1097 824 958 66 202 1101 545 1120 752 1432 496 1245 1448 164 332 1106 888 970 764 950 844 146 221 1166 36 1214 1116 889 1159 1007 662 1154 969 290 704 513 657 571 641 680 146 618 279 81 1009 728 1180 856 508 791 660 1107 409 212 896 1303 1467 27 222 1251 866 1489 239 572 1289 1133 1086 961 713 279 982 523 976 625 36 1360 140 207 850 330 119 164 194 598 361 694 295 952 1493 161 864 171 538 1307 765 966 881 1226 29 1107 298 816 1266 963 1357 1003 567 963 1097 702 609 1346 885 555 1468 162 1018 393 1183 403 45 1121 155 1244 100 71 996 505 104 1483 1308 927 358 442 166 1068 215 600 1116 1153 1163 961 918 544 708 354 531 932 1427 581 592 1119 544 629 434 1342 1352 41 740 562 1426 78…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route of the Garnet roads - MEDIUM Coding Problem | CodeTikki