[CCPC 2019 哈尔滨 ][CF 102394 E] Exchanging Gifts

题目描述:
题目链接: Codefoces E.Exchanging Gifts
题面:
After the dress rehearsal of CCPC Harbin Site 2019, m contestants are still in the contest arena. They are taking photos, discussing the problems, and exchanging gifts.

Initially, everyone has exactly one gift in their hand. Note that some contestants may have the same type of gifts. Specifically, the type of the gift in the i-th contestant’s hand can be represented as a positive integer gi. Two contestants i and j (1≤i,j≤m) share the same type of gifts if and only if gi=gj holds.

There can be many rounds of gift exchanging between these m contestants. In each round, two contestants may exchange their gifts with each other. Note that a pair of contestants can exchange gifts multiple times if they like. In the end, there will still be exactly one gift in each contestant’s hand.

Let’s denote hi as the type of gift in the i-th contestant’s hand in the end. If gi≠hi holds, the i-th contestant will be happy, because they have a different type of gift, otherwise they will be unhappy. Your task is to write a program to help them exchange gifts such that the number of happy contestants is maximized. For example, if g=[3,3,2,1,3] and h=[1,2,3,3,3], there will be 4 happy contestants.

Since m can be extremely large, you will be given n sequences s1,s2,…,sn, and the sequence g is equal to sn. The i-th (1≤i≤n) sequence will be given in one of the following two formats:

“1 k q[1…k]” (1≤k≤ 1 0 6 10^6 106, 1≤ q i q_i qi 1 0 9 10^9 109): It means s i s_i si=[ q 1 , q 2 , … , q k q_1,q_2,…,q_k q1,q2,,qk].
“2 x y” (1≤x,y≤i−1): It means s i = s x + s y s_i=s_x+s_y si=s

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值