← 返回题库
中级

Head of a Gang

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve(____):
    from collections import defaultdict
    threshold = int(____)
    total_time = defaultdict(____)
    connections = defaultdict(____)
    for call in str(____).split(____):
        parts = call.split(____)
        a, b, t = parts[____], parts[____], int(____)
        total_time[a] += t
        total_time[b] += t
        connections[a].add(____)
        connections[b].add(____)
    visited = set()
    gangs = []
    def dfs(____):
        visited.add(____)
        members.append(____)
        for nb in sorted(____):
            if nb not in visited:
                dfs(____)
    for person in sorted(____):
        if person not in visited:
            members = []
            dfs(____)
            total = sum(____) // ____
            if total > threshold and len(____) > ____:
                head = max(____)
                gangs.append((head, len(____)))
    for head, cnt in sorted(____):
        print(head + "____" + str(____))

示例

输入
AAA,BBB,10;BBB,CCC,20;CCC,AAA,30|20
期望输出
CCC 3
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码