中级
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
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199