cf468B Two Sets

Little X has n distinct integers: p1,?p2,?...,?pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:

  • If number x belongs to set A, then number a?-?x must also belong to set A.
  • If number x belongs to set B, then number b?-?x must also belong to set B.

Help Little X divide the numbers into two sets or determine that it‘s impossible.

Input

The first line contains three space-separated integers n,?a,?b (1?≤?n?≤?105; 1?≤?a,?b?≤?109). The next line contains n space-separated distinct integers p1,?p2,?...,?pn (1?≤?pi?≤?109).

Output

If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1,?b2,?...,?bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B.

If it‘s impossible, print "NO" (without the quotes).

Examples

Input

4 5 92 3 4 5

Output

YES0 0 1 1

Input

3 3 41 2 4

Output

NO

Note

It‘s OK if all the numbers are in the same set, and the other one is empty.

如果A中有了一个x,那么A中也要有a-x,说明(逆否命题)如果A中没有a-x,也就没有x。即如果B中有a-x,就有x。因为不在A就在B咯

所以这个A还是B无所谓的,重要的是x和a-x一定在同一集合,x和b-x一定在同一集合

因此裸并查集,只要被并起来的数字有一个不能在A,那么这一群都不能在A

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 using namespace std;
 4 LL n,a,b;
 5 inline LL read()
 6 {
 7     LL x=0,f=1;char ch=getchar();
 8     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
 9     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
10     return x*f;
11 }
12 struct po{LL x;int rnk;}p[100010];
13 bool operator <(po a,po b){return a.x<b.x;}
14 int fa[100010];
15 int mrk[100010];
16 inline int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}
17 map<LL,LL>mp;
18 int main()
19 {
20     n=read();a=read();b=read();
21     for (int i=1;i<=n;i++)
22     {
23         p[i].x=read();
24         p[i].rnk=i;
25     }
26     sort(p+1,p+n+1);
27     for(int i=1;i<=n;i++)mp[p[i].x]=p[i].rnk,fa[i]=i,mrk[i]=3;
28     for(int i=1;i<=n;i++)
29     {
30         if (mp[a-p[i].x])
31         {
32             int pos=getfa(mp[a-p[i].x]),pos2=getfa(p[i].rnk);
33             if (pos!=pos2)fa[pos2]=pos;
34         }
35         if (mp[b-p[i].x])
36         {
37             int pos=getfa(mp[b-p[i].x]),pos2=getfa(p[i].rnk);
38             if (pos!=pos2)fa[pos2]=pos;
39         }
40     }
41     for (int i=1;i<=n;i++)
42     {
43         int ff=getfa(p[i].rnk);
44         if (!mp[a-p[i].x])mrk[ff]&=1;
45         if (!mp[b-p[i].x])mrk[ff]&=2;
46     }
47     for (int i=1;i<=n;i++)
48         if (mrk[getfa(i)]==0){puts("NO");return 0;}
49         else if (mrk[getfa(i)]==3)mrk[getfa(i)]=1;
50     puts("YES");
51     for (int i=1;i<=n;i++)printf("%d ",mrk[getfa(i)]==2?0:1);
52     puts("");
53 }

cf468B

时间: 2024-12-27 23:38:44

cf468B Two Sets的相关文章

Simple Automated Backups for MongoDB Replica Sets

There are a bunch of different methods you can use to back up your MongoDB data, but if you want to avoid downtime and/or potential performance degradation, the most common advice seems to be that you should simply do all your backups on a slave. Thi

The Tree-planting Day and Simple Disjoint Sets

First I have to say: I have poor English. I am too young, too simple, sometimes na?ve. It was tree-planting day two weeks ago. SHENBEN dph taught us a lot about tree-planting and the disjoint sets. It was useful and valuable for a JURUO like me. I ad

并查集 (Union-Find Sets)及其应用

定义 并查集是一种树型的数据结构,用于处理一些不相交集合(Disjoint Sets)的合并及查询问题.常常在使用中以森林来表示. 集就是让每个元素构成一个单元素的集合,也就是按一定顺序将属于同一组的元素所在的集合合并. 主要操作 初始化 把每个点所在集合初始化为其自身. 通常来说,这个步骤在每次使用该数据结构时只需要执行一次,无论何种实现方式,时间复杂度均为O(N). 查找 查找元素所在的集合,即根节点. 合并 将两个元素所在的集合合并为一个集合. 通常来说,合并之前,应先判断两个元素是否属于

hdu 3836 Equivalent Sets【强联通】

Equivalent Sets Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 104857/104857 K (Java/Others) Total Submission(s): 3065    Accepted Submission(s): 1077 Problem Description To prove two sets A and B are equivalent, we can first prove A is a s

UVA 11488 Hyper Prefix Sets (Trie)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2483 Hyper Prefix Sets Prefix goodness of a set string islength of longest common prefix*number of strings in the set.For example the prefix goodnes

Terrible Sets

Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3017   Accepted: 1561 Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all real numbers. wi, hi for i = 1 . . . n are some elements in N, and w0

[转]SSIS Execute SQL Task : Mapping Parameters And Result Sets

本文转自:http://www.programmersedge.com/post/2013/03/05/ssis-execute-sql-task-mapping-parameters-and-result-sets.aspx#.U18_6PmSxBk A very common scenario in an ETL process is one in which you need to call out to some configuration tables to figure out so

MongoDB设置 Replication Sets

MongoDB 高可用可用分两种 : Master-Slave 主从复制 :只需要在某一个服务启动时加上–master 参数, 而另一个服务加上–slave 与–source 参数, 即可实现同步. MongoDB的最新版本已不再推荐此方案. Replica Sets 复制集 :MongoDB 在 1.6 版本对开发了新功能 replica set,这比之前的 replication 功能要强大一 些,增加了故障自动切换 和自动修复成员节点,各个 DB 之间数据完全一致,大大降低了维 护成功.a

Generating Sets 贪心

H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description You are given a set Y of ndistinct positive integers y1,?y2,?...,?yn. Set X of ndistinct positive integers x1,?x2,?...,?xn is