CT54468

Viktor's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the northern keep of Frostgate, Viktor the log keeper keeps careful count of the roads. Forecast next month's demand, every figure matters. 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 <= 3683; 0 <= m <= 3683.

Example 1:

Input: 542 306 506 398 179 330 121 4 387 208 230 527 199 296 355 118 84 484 354 62 250 243 484 70 40 273 175 370 247 9 187 433 446 58 194 196 221 101 79 387 59 286 312 438 323 258 409 316 187 185 494 158 33 348 111 323 416 324 308 515 485 35 204 108 397 178 38 22 276 501 442 11 320 5 191 477 149 128 69 96 1 311 179 194 81 542 334 450 436 426 159 24 221 22 448 215 406 295 514 340 373 526 334 519 388 523 483 164 427 276 224 397 232 316 438 340 18 375 61 413 287 244 358 442 124 334 172 316 209 232 131 122 219 17 512 202 54 229 413 205 204 445 399 464 244 503 317 449 94 436 79 216 116 107 285 473 167 97 464 353 192 164 438 348 86 274 124 295 5 403 53 278 4 269 319 276 274 268 528 239 478 170 179 188 201 246 148 134 152 307 253 209 229 138 489 108 206 174 522 324 497 341 130 495 29 460 396 222 227 380…
Output: NO

Example 2:

Input: 462 2669 266 24 42 382 462 58 97 55 261 220 411 456 221 390 169 2 301 243 44 285 407 236 434 298 152 301 33 355 410 8 127 214 336 330 425 16 333 407 327 114 428 2 378 122 447 439 299 55 138 34 371 376 113 177 309 325 448 272 197 229 150 381 331 104 3 182 132 187 43 35 335 274 188 29 365 81 299 21 208 410 434 93 1 443 382 104 170 398 260 247 320 391 397 282 49 174 442 172 449 291 113 193 343 408 86 177 285 352 29 448 70 219 311 211 402 116 82 266 287 231 335 205 164 48 61 178 413 317 323 165 19 370 81 344 346 335 238 342 87 145 143 125 388 360 327 291 266 322 306 162 64 11 230 164 293 146 354 346 139 82 114 425 95 58 153 57 306 111 187 75 80 455 429 343 146 413 373 259 44 158 209 164 140 414 462 32 37 338 281 192 192 77 457 291 356 278 401 72 353 346 392 182 194 135 424 68 101 192 8 281 231…
Output: YES

Example 3:

Input: 2935 2442 1074 1196 1363 184 1966 436 1768 2524 2797 1345 899 523 1766 200 1859 649 2617 865 1460 216 2390 1556 717 118 1270 2509 1471 2798 334 2866 829 2365 2427 162 483 835 1836 1719 944 2747 2002 889 504 2712 1794 644 2183 2870 2506 1983 838 305 1944 537 260 1736 1690 233 2310 2697 72 1839 161 2849 2170 2124 2246 957 2160 448 1985 1286 2551 1672 142 1176 32 1521 2381 1839 499 646 1321 1412 2873 2133 2739 916 1054 213 2595 1364 882 2069 288 1162 2559 183 1837 329 1803 2319 745 297 1801 692 1453 398 2848 197 1588 1589 252 1634 876 2884 2831 832 741 325 1688 2235 81 2521 1190 2493 1134 1763 1488 926 2026 2667 1504 2032 693 158 2190 2756 2379 933 1651 1168 1347 92 207 365 2890 2404 1369 904 2858 2456 1694 1160 1191 1132 1862 2626 1797 819 2883 2044 1028 1977 2280 1329 2028 382 1502 13 2196 …
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Viktor's Circular Route Ledger - MEDIUM Coding Problem | CodeTikki