CT49211

Vani and the Circular Route

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the mulberry rows of Silkmead with crates of roads, and Vani the quartermaster must account for every last one. 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 <= 2614; 0 <= m <= 2614.

Example 1:

Input: 1239 1818 784 627 1126 1036 644 156 587 100 114 1073 219 317 565 790 169 556 991 731 367 387 591 541 244 555 1060 1077 396 176 1216 989 855 225 72 1206 550 14 1083 27 513 254 1150 240 238 1195 680 576 712 368 109 181 19 685 653 708 296 350 1112 738 356 961 367 299 972 414 634 347 451 440 630 985 296 491 436 763 142 240 280 1039 1163 841 762 393 1044 282 41 495 229 825 710 333 565 388 823 776 230 533 743 133 959 1191 208 1018 908 747 493 1106 532 812 506 1171 412 1188 4 70 347 112 1017 151 796 601 516 936 615 51 361 839 559 340 826 830 1223 479 1227 910 997 17 1129 71 1005 134 449 1149 1097 1046 493 948 557 279 55 722 956 1050 1032 355 258 579 945 581 498 410 689 1114 978 695 515 423 566 507 633 389 354 460 424 64 171 588 1210 780 1116 778 193 1116 968 128 508 918 780 590 7 1135 852 539 959…
Output: YES

Example 2:

Input: 1909 587 569 1330 504 903 1563 1326 1907 339 1449 1340 652 150 329 1085 664 1361 1670 366 1094 282 1358 789 937 1794 1790 1153 1779 290 1310 84 700 539 291 122 1660 1051 360 1338 558 1859 960 634 786 665 134 850 1720 516 756 1379 398 1712 1836 1427 1533 1782 573 1858 755 1144 564 1447 505 977 553 664 952 614 634 293 807 277 1104 353 1900 1135 1136 1589 898 1684 751 1608 912 1509 1716 1127 278 1103 1200 1682 1000 766 888 553 1213 107 1015 762 1406 835 769 640 526 1396 1609 1495 1287 852 210 1341 455 636 1426 321 834 198 466 779 76 513 1779 336 1557 1558 1499 332 1017 487 1143 1192 572 171 1455 1323 204 1239 1381 900 1632 607 1614 1471 63 1047 130 399 195 423 315 564 784 1703 357 1636 1363 564 545 1534 255 1878 1193 1203 778 402 380 1642 1538 385 1104 1327 1652 1261 60 827 1611 18 1289 216 2…
Output: NO

Example 3:

Input: 256 2013 124 242 3 185 109 144 114 190 7 58 7 158 185 132 134 3 146 5 97 170 204 243 225 249 250 214 128 35 84 133 201 200 184 5 34 256 61 169 166 137 4 232 45 218 115 87 163 3 238 222 26 164 226 239 235 133 176 226 252 156 250 23 116 111 91 228 246 74 80 5 224 189 135 202 2 99 42 154 84 246 24 209 124 96 38 134 84 167 73 245 20 234 236 3 63 128 101 233 9 191 237 27 138 212 12 149 188 207 214 240 58 232 102 96 82 227 99 235 146 248 111 244 159 154 81 117 16 159 41 145 97 222 121 6 189 210 150 235 208 153 134 221 141 149 189 73 164 141 13 54 100 246 50 250 38 95 44 199 174 203 164 232 198 102 178 16 22 113 80 215 203 174 134 101 142 188 118 234 55 24 39 134 62 4 94 146 145 23 91 138 240 67 249 37 200 28 209 94 230 185 202 166 66 229 115 220 23 67 247 244 166 194 163 34 13 46 155 132 238 47 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.