def depth_limited_search(graph, start, goal, depth_limit):
def dls(node, depth):
if depth > depth_limit:
return False
if node == goal:
return True
for neighbor in graph.get(node, []):
if dls(neighbor, depth + 1):
return True
return False
return dls(start, 0)
# Example Usage
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': [],
'F': []
}
print(depth_limited_search(graph, 'A', 'E', 2)) # Output: True
print(depth_limited_search(graph, 'A', 'F', 1)) # Output: False
ZGVmIGRlcHRoX2xpbWl0ZWRfc2VhcmNoKGdyYXBoLCBzdGFydCwgZ29hbCwgZGVwdGhfbGltaXQpOgogICAgZGVmIGRscyhub2RlLCBkZXB0aCk6CiAgICAgICAgaWYgZGVwdGggPiBkZXB0aF9saW1pdDoKICAgICAgICAgICAgcmV0dXJuIEZhbHNlCiAgICAgICAgaWYgbm9kZSA9PSBnb2FsOgogICAgICAgICAgICByZXR1cm4gVHJ1ZQogICAgICAgIGZvciBuZWlnaGJvciBpbiBncmFwaC5nZXQobm9kZSwgW10pOgogICAgICAgICAgICBpZiBkbHMobmVpZ2hib3IsIGRlcHRoICsgMSk6CiAgICAgICAgICAgICAgICByZXR1cm4gVHJ1ZQogICAgICAgIHJldHVybiBGYWxzZQoKICAgIHJldHVybiBkbHMoc3RhcnQsIDApCgojIEV4YW1wbGUgVXNhZ2UKZ3JhcGggPSB7CiAgICAnQSc6IFsnQicsICdDJ10sCiAgICAnQic6IFsnRCcsICdFJ10sCiAgICAnQyc6IFsnRiddLAogICAgJ0QnOiBbXSwKICAgICdFJzogW10sCiAgICAnRic6IFtdCn0KcHJpbnQoZGVwdGhfbGltaXRlZF9zZWFyY2goZ3JhcGgsICdBJywgJ0UnLCAyKSkgICMgT3V0cHV0OiBUcnVlCnByaW50KGRlcHRoX2xpbWl0ZWRfc2VhcmNoKGdyYXBoLCAnQScsICdGJywgMSkpICAjIE91dHB1dDogRmFsc2U=