bilingual-math-code-verification-v1 / code /math_code_006_verify.py
efe-T's picture
Upload folder using huggingface_hub
93237a0 verified
Raw History Blame Contribute Delete
551 Bytes
edges = [("A","B",2),("A","C",3),("B","C",1),("B","D",4),
("C","D",2),("C","E",3),("D","E",1)]
paths = []
def visit(path, cost):
if path[-1] == "E":
paths.append((path, cost))
return
for u, v, weight in edges:
if u == path[-1] and v not in path:
visit(path + [v], cost + weight)
visit(["A"], 0)
best = min(cost for _, cost in paths)
result = {"distance": best, "shortest_path_count": sum(cost == best for _, cost in paths)}
import json
print(json.dumps(result, ensure_ascii=False, sort_keys=True))