CT50386

Librarian's Ledger of corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the acacia flats of Thornveld; Librarian weighs the day's corridors manifests and starts the calculations. 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 <= 2214; 0 <= m <= 2214.

Example 1:

Input: 1435 714 142 1039 956 1230 668 362 1065 1064 926 540 582 214 1325 925 97 932 1261 225 455 1016 346 681 240 1017 1183 842 981 223 310 726 392 324 535 770 1298 1427 437 1276 683 410 135 1411 609 1009 677 1335 144 503 934 1405 342 434 299 979 436 95 1345 516 593 634 1233 78 590 692 498 1286 515 306 676 1247 1282 489 1366 704 642 1405 99 739 792 1174 1279 684 388 355 1255 586 148 998 307 949 490 738 715 599 1038 541 900 433 469 1191 574 1354 1435 858 622 293 165 598 626 1268 541 1050 158 465 213 1074 656 799 1168 242 587 1377 630 740 1223 868 153 1235 1179 447 932 279 583 1409 1389 142 1203 1186 1219 1026 932 1257 1015 1396 505 287 700 261 1097 1155 161 1411 105 132 299 823 850 1366 993 901 639 817 1083 625 421 1082 1383 939 958 285 51 64 314 91 27 718 390 1161 203 746 714 968 231 683 117 975 …
Output: NO

Example 2:

Input: 48 400 45 48 23 48 36 32 46 41 30 37 33 13 4 37 37 15 39 35 31 47 43 3 3 27 45 14 44 30 28 21 40 11 10 28 22 13 42 41 18 28 3 21 13 11 37 17 40 25 38 33 28 11 44 13 13 6 12 47 48 12 3 19 25 14 47 28 5 19 9 31 18 40 18 10 14 27 41 19 9 33 36 41 34 28 22 28 7 31 48 35 48 2 1 30 13 7 1 37 2 38 41 22 8 25 39 6 27 16 2 14 11 28 4 13 10 35 32 38 45 17 10 9 20 5 9 42 44 32 35 47 14 36 43 13 39 29 22 47 37 4 23 40 48 1 8 3 3 13 43 12 26 47 41 17 23 1 33 28 34 23 36 3 32 13 19 32 38 21 16 1 20 6 48 33 37 26 3 16 37 40 27 10 8 5 10 48 26 18 42 21 31 27 47 41 7 17 30 36 23 15 31 22 38 31 16 29 11 48 25 1 21 6 28 20 24 43 11 6 1 33 25 37 8 45 47 1 31 25 4 35 35 3 48 6 43 16 8 7 41 35 17 48 40 17 19 17 48 46 10 19 46 45 2 47 37 16 4 19 10 17 21 7 3 26 46 24 1 28 7 39 7 26 46 9 13 26 44 33 43 37 5 33 15…
Output: YES

Example 3:

Input: 1384 422 1149 1235 409 1270 1329 1238 1026 714 493 1071 789 1184 616 1054 100 775 1053 1014 1290 859 64 588 1361 870 40 84 620 371 361 638 1382 1084 700 229 692 454 1005 58 602 446 534 946 782 609 1248 208 109 1380 989 829 898 935 1301 74 1042 324 842 344 418 636 45 270 714 586 1042 667 208 236 801 70 1358 362 1211 208 36 424 66 363 1 463 1335 502 1173 435 967 238 1211 134 923 932 19 644 1220 475 111 965 1146 202 889 76 563 335 454 30 122 243 722 1042 1162 853 1064 1165 1217 136 930 141 607 885 682 426 1149 510 91 614 1120 789 321 476 514 1112 1357 351 359 335 869 1192 1132 288 273 357 529 1107 432 972 1082 688 538 569 1047 692 593 149 1069 1370 1103 947 323 564 484 32 150 1227 1311 1055 808 742 421 708 1092 1073 359 946 201 429 1139 74 613 275 848 1238 123 1179 674 908 456 1030 861 996 26…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Librarian's Ledger of corridors - MEDIUM Coding Problem | CodeTikki