2.We Are A Team----OD

# 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")


  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值