CT49824

Porter's Wayward corridors

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the desert outpost of Sandspire. Porter spreads the corridors records across the table and picks up a sharp pencil. 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 <= 2564; 0 <= m <= 2564.

Example 1:

Input: 2135 1100 1209 2057 48 1346 1324 75 891 1439 661 1508 1816 826 483 909 1347 563 1527 1259 1141 1099 156 1790 482 20 933 540 1423 1593 1806 1155 1799 786 402 43 1533 1273 323 88 837 1432 2091 1342 13 15 1706 1319 1063 1152 1904 240 760 1205 98 614 1073 1120 751 1833 1398 1282 1802 1348 1542 151 1577 549 1400 435 1856 1695 876 500 1079 44 1223 1111 1880 690 1903 179 2090 993 1145 942 1409 95 1306 621 464 144 1475 1341 188 228 860 1135 791 2042 2054 1232 746 112 861 1836 772 1043 1231 1264 1791 1505 1258 1165 1233 952 1593 1870 512 238 602 417 1990 2022 1959 1467 987 364 1903 1448 1886 1086 1140 504 593 849 463 1548 248 2079 1699 1389 1394 348 1661 132 1557 1983 1415 186 2052 950 971 1816 1547 361 952 165 666 982 1682 1358 1374 1057 42 1048 707 1181 1181 768 1293 248 303 331 1958 394 1902 172…
Output: NO

Example 2:

Input: 401 2297 300 59 31 186 39 209 281 382 219 277 298 149 229 346 150 395 272 229 276 395 269 244 134 171 98 137 141 350 92 73 283 178 159 237 133 173 388 39 89 328 257 212 387 240 129 329 67 274 21 350 364 54 341 280 151 165 239 205 197 128 131 93 136 55 356 28 14 77 152 134 362 193 362 143 169 252 44 304 160 191 199 396 171 228 273 69 32 244 110 48 250 4 363 373 70 328 29 202 128 34 158 368 129 143 273 235 174 224 178 100 399 196 322 44 122 82 307 333 369 121 257 349 384 378 244 314 172 319 32 260 337 134 266 230 343 47 260 58 183 287 375 350 19 41 302 92 259 116 271 230 148 14 335 305 135 371 142 204 389 175 223 263 302 398 167 294 332 94 142 206 381 58 198 396 217 12 232 392 294 324 97 246 183 150 333 322 349 330 63 125 386 368 164 169 30 280 35 163 112 27 1 123 42 56 297 10 252 97 370 109…
Output: YES

Example 3:

Input: 216 1057 174 72 159 118 105 205 10 83 133 142 108 200 81 43 43 107 48 201 126 202 85 135 63 138 146 97 60 215 11 105 38 205 207 161 151 118 74 168 86 130 33 4 92 150 182 37 202 34 106 89 205 53 106 175 201 104 83 117 188 59 146 112 5 1 216 101 105 151 105 28 14 169 198 204 176 94 171 79 67 55 7 183 27 201 169 109 179 208 101 4 13 85 55 202 128 11 128 86 209 14 179 198 193 204 163 79 96 166 132 26 55 124 66 74 35 143 206 139 87 22 200 193 211 19 213 63 49 105 144 165 122 22 146 19 36 103 62 37 127 183 138 114 93 22 79 1 37 69 66 38 88 181 100 46 14 161 62 200 125 66 156 91 70 21 160 43 58 78 134 206 17 209 137 71 151 94 8 126 157 203 8 174 197 172 199 209 10 31 149 60 136 57 183 169 135 187 140 121 75 121 58 121 190 162 138 60 6 10 33 36 142 13 71 139 147 94 97 71 15 210 60 14 70 184 189 5 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Porter's Wayward corridors - MEDIUM Coding Problem | CodeTikki