CT55758

Last bridges of June

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

June the store warden watches over the foggy moor of Greyfen's stores of bridges. A careful computation stands between order and chaos. 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 <= 3730; 0 <= m <= 3730.

Example 1:

Input: 3528 1775 421 22 2062 2923 1647 3103 642 2534 2216 1018 2842 320 1443 1889 1875 434 3373 189 3103 3283 809 2492 1049 13 438 308 3390 1955 1563 790 2939 2324 655 1936 655 865 1509 2137 1275 1590 804 693 690 54 1177 2868 1006 1091 864 1901 1693 623 1255 2761 1566 3277 1556 309 3005 564 1744 52 2721 2485 35 753 93 1208 2815 1629 511 1150 2985 1621 3123 3011 793 2035 2622 1949 1893 1790 2052 178 2466 2868 1504 2227 1166 3102 2079 2070 206 885 1234 1646 238 6 3436 2617 986 2008 1324 1921 137 621 2224 116 1300 664 3501 890 2385 1665 1064 3392 1693 1237 3469 1181 927 2234 721 1480 1564 2597 2836 2414 2608 2796 1885 1447 3059 3186 860 1063 574 1739 221 763 1465 3151 1961 2583 1752 3023 1926 103 2539 2449 2834 5 1384 1032 17 2629 3268 3345 912 1348 1665 2343 2480 2178 2808 579 2831 2504 650 1386 28…
Output: NO

Example 2:

Input: 3082 337 1882 292 785 2798 1112 2102 2311 394 1191 1720 2842 2477 1454 2408 829 1425 1549 3060 2832 2159 1395 1588 2280 2276 1095 1579 2315 1454 478 573 618 899 2486 1075 1389 771 2771 794 578 2376 2027 2350 3026 1775 2933 1352 444 2431 1589 152 60 959 1349 485 2221 678 2774 617 948 102 182 3034 1670 1495 812 1071 69 2676 727 719 1967 167 1732 1850 1375 1407 446 2175 3031 856 2483 1930 1966 444 2998 550 2439 2380 2180 2583 876 576 969 2919 2755 2524 3000 1002 800 17 2059 2335 1734 1784 1734 1991 1465 924 2989 2194 499 439 534 2531 2810 2466 985 306 2363 408 443 691 21 2630 107 1627 1213 2397 398 531 1113 2782 1624 2849 2424 2713 2597 1577 2233 2740 2137 2699 2363 2832 1921 473 908 220 1491 1105 1074 277 1451 1771 2391 2371 152 2818 281 305 448 210 303 1268 2353 210 2602 2973 892 1232 1744 …
Output: NO

Example 3:

Input: 1527 1412 291 849 1365 1319 65 713 1136 202 443 1140 783 558 58 181 700 221 463 21 37 146 454 985 1470 909 1109 1055 293 562 1399 921 242 1345 41 1345 877 1458 103 801 1211 926 224 635 677 259 136 60 509 1196 1168 341 1473 1147 1431 1132 67 183 935 1429 530 365 1157 308 81 964 846 23 25 630 623 533 1165 1502 135 766 941 404 1447 14 1109 1010 917 45 307 783 1033 1466 838 1469 930 881 413 419 238 558 1023 1196 1210 1112 503 652 101 672 686 648 401 236 569 487 596 1465 1405 967 471 368 68 903 156 1428 5 368 400 1013 1349 1194 625 1246 299 169 823 489 1392 928 144 200 129 8 666 608 204 633 1126 1321 107 243 1038 573 1198 264 1255 180 1134 1199 446 1398 1073 1170 1179 107 883 925 1339 1451 1151 1363 274 39 193 355 1488 1255 977 53 724 1005 1424 103 204 1094 852 162 1260 494 442 24 744 204 412 5…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last bridges of June - MEDIUM Coding Problem | CodeTikki