CT50756

The Circular Route of Glowtide

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Lakshya found an old ledger of roads in the loft attic at the lantern reef of Glowtide. 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 <= 3503; 0 <= m <= 3503.

Example 1:

Input: 1304 2539 342 743 976 850 118 755 664 1218 898 5 500 463 1295 342 731 485 84 1259 76 104 58 78 1213 1250 912 711 1036 482 808 47 916 996 647 172 1175 686 127 1242 297 1224 1290 642 497 1067 1168 120 523 304 519 943 1076 626 1259 766 1179 1008 104 565 790 687 839 778 831 78 984 442 371 29 630 294 809 1231 166 398 932 955 1162 323 861 1303 1042 871 1042 691 1255 84 756 766 658 330 1266 247 979 1044 128 848 770 403 51 250 723 507 1286 785 552 812 30 845 754 162 251 1042 58 699 145 453 461 281 509 1193 440 777 301 49 1166 955 739 1245 971 217 598 1245 1019 1055 339 786 359 593 1184 482 530 755 32 613 494 866 461 730 166 1270 548 928 746 1045 1304 369 267 528 691 644 1171 291 425 72 724 528 840 267 470 724 867 725 661 77 917 1155 925 147 1103 622 1267 214 45 1178 311 367 744 1094 132 718 463 37…
Output: YES

Example 2:

Input: 446 573 284 443 34 91 68 107 51 99 100 362 99 68 382 81 196 85 198 70 89 418 149 286 399 339 218 43 24 394 383 251 28 43 399 218 34 197 323 145 38 22 339 414 404 384 49 224 105 300 350 73 161 42 247 90 250 47 333 19 346 412 15 261 119 106 311 125 371 331 426 4 135 145 300 229 356 330 349 271 252 115 138 433 196 106 250 282 404 361 346 361 328 119 414 262 49 27 236 20 364 134 251 250 76 160 369 227 92 164 57 158 68 429 142 73 13 38 431 260 67 32 311 397 238 265 347 326 15 8 50 87 118 67 250 408 221 410 263 358 122 224 261 13 277 104 182 365 184 190 72 178 85 257 255 122 374 307 118 111 221 156 190 432 361 168 240 75 228 341 36 410 219 220 257 316 145 436 313 157 150 115 212 441 265 235 181 266 313 84 139 109 322 341 211 11 342 151 45 49 2 284 253 100 333 240 281 341 122 402 265 426 219 233 …
Output: YES

Example 3:

Input: 370 2061 311 242 197 18 273 361 224 78 127 310 256 251 260 299 134 163 120 262 308 235 61 282 88 96 249 132 80 5 368 160 186 27 20 114 332 28 320 269 187 231 278 94 341 298 240 345 295 186 139 231 202 326 198 310 27 254 319 28 207 148 367 157 329 223 348 24 243 146 245 109 73 5 93 16 149 199 90 96 210 312 297 338 37 246 215 57 148 283 358 367 76 137 191 8 334 125 6 162 195 263 109 229 357 63 162 364 23 274 112 217 323 265 133 96 317 318 370 274 164 58 319 106 323 101 115 141 207 1 210 107 88 298 361 187 365 167 330 51 282 295 86 264 322 100 148 256 180 322 287 241 146 70 240 187 362 5 186 85 239 157 89 164 353 31 283 278 67 269 361 170 340 285 92 184 65 39 48 168 315 325 100 84 65 270 263 25 355 298 218 295 36 3 93 131 2 21 122 292 361 292 140 40 81 78 125 309 284 169 246 21 363 15 78 54 3…
Output: YES

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Circular Route of Glowtide - MEDIUM Coding Problem | CodeTikki