# 5 7 # 1 2 0 # 4 5 0 # 2 3 0 # 1 2 1 # 2 3 1 # 4 5 1 # 1 5 1 # # We are a team # We are a team # We are a team # We are not a team # # 总共有n个人在机房,每个人有一个标号,他们分为多个团队,需要你根据收到的消息判断两个人是否属于一个团队 # 消息队列a b c ,整数a b 代表两个人的标号,整数c代表指令 # c == 0 代表a b 在一个团队, # c ==1 代表需要判定a b 的关系 # 如果a b是一个团队,输出we are a team # 如果不是,输出we are not a team # c 为其他值或当前行a或b超出1-n范围,输出da pian zi import sys n, m = map(int, sys.stdin.readline().split()) relationship_sets = [] verify_relationships = [] for i in range(m): relationship = sys.stdin.readline().strip().split() x, y, relation = map(int, relationship) if relation != 0: verify_relationships.append(relationship) else: set_added = False for j in range(len(relationship_sets)): # print("relationship_sets", relationship_sets) set_ = relationship_sets[j] if x in set_ or y in set_: set_.add(x) set_.add(y) set_added = True break if not set_added: new_set = set() new_set.add(x) new_set.add(y) relationship_sets.append(new_set) for i in range(len(verify_relationships)): relationship = verify_relationships[i] x, y, relation = map(int, relationship) if relation != 1: print("da pian zi") continue is_team = False for j in range(len(relationship_sets)): set_ = relationship_sets[j] if x in set_ and y in set_: print("we are a team") is_team = True break if not is_team: print("we are not a team")
2.We Are A Team----OD
于 2024-03-24 18:01:59 首次发布