跳到正文

题解

CF468B题解

Ag2WO4约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年8月6日
收录
2025年12月12日
更新
2026年10月31日
篇幅
约 2 分钟
题目
CF468B

版本

  1. v1当前

前排提示:这其实真的是水题!

考虑根据可放置的集合建图,由于只有两个集合,边最多两条,只能成线或者简单环。对于线,显然偶数长度有解奇数长度无解;而对于简单环的情况,特判即可:

  • a=ba=b 时两条边连接两点(若 x=a/2=b/2x=a/2=b/2 则为一点),此时该简单环必然有解;
  • 若不然,当 xx 存在时两步变换可推 x+a−bx+a-b 存在,此时沿环的一个方向无限前进无法回到 xx 本身,推出矛盾。

寻找线的端点(边数小于二),遍历线的长度,最终特判环即可。

Python
a,b,c=map(int,input().split());a={i:-1 for i in map(int,input().split())}
for i in a:
    if-1==a[i]:
        if b-i not in a or c-i not in a:
            d=i;e=f=0
            if b-i not in a:f=1
            while 1:
                a[d]=f
                if e:
                    if f:
                        if b-d not in a:break
                    elif c-d not in a:break
                else:
                    if f:
                        if c-d not in a:print('NO');exit()
                    elif b-d not in a:print('NO');exit()
                d=c-d if e^f else b-d;e^=1
print('YES');print(*(abs(a[i])for i in a))
原文