CT43569

The Woven corridors of Lila

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Lila found an old ledger of corridors in the ropewalk attic at the frontier camp of Duskwood. The margin notes pose a precise question. 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 <= 3715; 0 <= m <= 3715.

Example 1:

Input: 1813 1060 106 1710 123 1466 1581 800 1024 1537 754 894 1262 293 1457 1493 405 1656 1129 1297 1677 499 76 1078 1414 128 1574 345 948 518 384 1310 1596 805 1158 786 1411 1323 1219 956 1186 735 27 1502 592 1519 341 481 890 1287 1227 447 824 1181 276 579 1081 175 1251 1202 403 1443 962 760 1582 887 1765 1629 1501 1405 628 1530 123 717 189 256 407 287 1688 1427 962 1202 252 205 1332 1699 515 739 262 1155 1317 1766 543 252 775 660 1044 202 27 1724 152 110 895 1308 855 1486 697 311 1534 121 1606 1378 404 1793 1723 394 1270 1688 664 1738 107 1085 1527 1738 533 89 1058 451 338 613 1420 1196 535 1128 559 705 183 1174 1708 104 295 173 74 906 453 307 47 37 220 1500 1720 1162 58 1794 1693 438 718 1031 1578 13 844 1074 589 663 854 876 888 656 764 466 1683 1268 852 833 1592 1399 1036 1587 1326 388 176 11…
Output: NO

Example 2:

Input: 658 3430 495 361 602 51 78 578 119 377 44 505 152 252 170 399 64 341 367 385 356 54 453 358 190 568 303 460 102 216 602 483 602 452 42 221 617 162 485 239 229 470 172 70 600 222 567 232 524 388 482 643 583 468 335 359 136 205 178 153 609 78 152 315 364 399 617 31 267 600 18 287 431 540 294 22 508 286 279 370 12 277 371 87 124 310 649 356 214 286 260 469 488 310 493 206 88 478 502 578 534 524 88 352 326 529 129 582 74 361 111 281 546 421 570 148 77 614 84 82 39 187 513 126 5 276 213 410 307 492 93 354 395 322 400 416 605 626 170 127 301 477 481 187 111 283 1 245 318 599 371 403 635 331 164 282 223 597 354 352 202 182 584 232 72 642 558 222 497 344 322 313 244 573 550 2 209 576 212 160 507 313 631 639 548 658 25 547 257 476 345 350 386 477 389 147 398 423 281 423 25 191 468 218 307 548 7 280…
Output: YES

Example 3:

Input: 1586 704 219 1003 396 711 1076 910 905 1271 551 1446 680 157 1099 534 607 1497 731 335 1330 53 1195 879 800 1429 1068 1132 1025 1050 732 1449 1155 398 248 505 1046 1342 386 764 355 1543 480 128 794 472 226 114 517 330 1008 637 1065 335 1559 1240 9 380 530 1361 1010 780 1424 408 194 1523 39 132 67 679 1128 262 1582 926 386 1370 195 241 138 541 527 501 346 1534 698 1320 1197 792 781 1344 1145 202 503 999 489 1412 329 552 1377 1367 95 357 1219 606 834 1034 1413 1175 1107 1005 1365 1376 1403 740 844 1559 1173 830 855 1407 1048 616 1128 659 453 1056 953 118 1298 1432 1095 133 1055 1218 411 748 389 724 10 5 211 674 307 1124 1016 1182 1528 1574 532 1000 1287 824 770 1423 720 743 659 1278 110 457 776 304 397 796 1167 618 258 1160 1090 1432 924 730 541 1244 1164 306 1171 91 1260 1222 1434 293 155 1…
Output: NO

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Woven corridors of Lila - MEDIUM Coding Problem | CodeTikki