CT45470

Ojas's Circular Route Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the beacon hill of Lantern Tor close for winter, Ojas must finish the roads ledger - one figure at a time. 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 <= 2052; 0 <= m <= 2052.

Example 1:

Input: 227 72 17 25 87 62 148 84 155 16 121 197 200 226 97 219 12 61 70 124 215 43 211 222 204 66 191 118 182 114 83 145 218 127 20 50 4 85 218 116 215 204 48 144 184 143 29 101 209 134 60 48 72 199 5 175 180 170 15 3 80 108 122 100 92 84 56 84 71 26 113 83 34 44 186 100 178 176 103 151 27 130 108 176 69 77 196 129 190 152 221 146 31 71 169 63 212 91 182 82 221 151 227 226 173 98 226 49 186 36 96 20 216 210 110 182 30 112 84 68 54 19 111 93 197 7 181 132 167 129 193 152 135 168 118 122 205 3 77 177 92 25 224 86 115 107
Output: NO

Example 2:

Input: 1510 592 765 243 901 553 210 164 114 1408 1246 390 720 878 1499 774 1062 904 1236 392 1480 1186 998 652 898 101 313 1198 1110 325 759 803 36 1137 351 1195 446 91 192 1157 69 834 44 1230 764 688 1380 701 202 114 331 356 780 1333 1343 782 602 1128 1179 1212 575 343 38 1256 336 1089 598 454 807 932 679 1262 1436 71 721 481 1497 37 1303 121 335 696 1383 491 429 987 1468 377 961 745 436 96 189 1209 376 1035 1375 1364 357 852 1425 298 1266 1403 80 1308 578 1415 74 386 33 743 753 241 931 582 1396 1204 22 340 1100 1495 815 1444 1224 104 285 1109 41 756 179 1501 176 573 734 623 1163 245 1198 200 319 352 328 18 1136 1118 1319 255 267 858 136 418 413 19 192 393 608 334 111 754 457 1146 1459 1017 1375 775 713 1435 293 352 628 342 650 221 447 927 1083 1451 739 289 128 827 778 487 928 263 840 562 320 97…
Output: NO

Example 3:

Input: 341 1488 134 176 114 82 96 240 224 55 123 338 273 80 312 130 161 13 321 135 226 313 138 167 58 251 197 280 34 49 317 159 222 286 66 206 172 223 160 4 213 281 229 93 102 62 107 63 124 175 169 232 167 156 162 143 176 73 2 273 216 77 254 200 163 124 261 172 105 261 165 34 98 211 262 123 96 18 319 303 129 285 269 145 188 276 152 57 340 319 213 279 328 100 321 178 213 308 131 173 188 201 250 102 324 142 234 37 312 150 237 28 314 176 329 301 117 114 214 302 76 220 167 281 181 333 222 168 105 162 27 285 246 76 229 334 208 164 217 109 58 331 37 259 278 91 73 227 55 264 108 249 269 122 327 200 43 259 14 175 23 229 124 204 32 148 34 39 92 273 164 148 32 11 63 294 248 237 78 36 77 234 77 152 235 319 54 55 246 172 85 48 182 111 302 300 78 50 120 300 155 72 158 32 307 192 181 127 214 121 36 183 221 18 …
Output: YES

Constraints:

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

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