【发布时间】:2022-09-30 21:51:06
【问题描述】:
我的代码是这样的,输入在这里。
5 6
1 2
1 5
2 4
3 4
3 5
4 5
当我输入 2 4 时,值 root_a 为无。但我不明白为什么 root_a 返回 None 。我试图在 pycharm 上调试,但我不知道为什么...... 有人可以帮忙吗?
node, edge = list(map(int, input().split()))
root_list = [x for x in range(node)]
def find_root(x):
print(x, \'x\')
if x == root_list[x]:
return x
root_x = find_root(root_list[x])
root_list[x] = root_x
for _ in range(edge):
a, b = list(map(int, input().split()))
a = a - 1
b = b - 1
root_a = find_root(a)
root_b = find_root(b)
print(root_a, root_b, \'root\')
if root_a != root_b:
root_list[b] = root_a
print(root_list)
标签: python python-3.x