只在 main 上的提交有几个

👁️ 3 人浏览 💬 0 人评论 ❤️ 添加收藏

接着用集合相减。运行下面这段程序:

def ancestors(g, c):
    seen = set()
    st = [c]
    while st:
        x = st.pop()
        if x in seen:
            continue
        seen.add(x)
        st.extend(g[x])
    return seen

def only_on(g, a, b):
    return ancestors(g, a) - ancestors(g, b)

g = {'3f2a91c': [],
     '7b4e2d0': ['3f2a91c'],
     'a1c5f83': ['7b4e2d0'],
     'e90d417': ['7b4e2d0'],
     '5c8b206': ['e90d417']}
print(len(only_on(g, 'a1c5f83', '5c8b206')))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论