Collection issues
Test instructions
Give you A, B and n number P[i], ask how you assign this n number to a A, a, and meet:
If X is in set a, then A-x must also be in collection A.
If x is in set B, then b-x must also be in set B.
Train of thought: and check the operation, oneself mainly did not think to use map to map 1e9-->1e5;
#include <iostream>#include<cstring>#include<string>#include<algorithm>#include<cstdio>#include<map>using namespacestd;Const intMAXN = 1e5+7;intN,a,b,fa[maxn],a[maxn];map<int,int>MP;voidinit () { for(intI=0; i<=n+1; i++) Fa[i]=i;}intFindintx) { if(fa[x]==x)returnx; Else returnFA[X] =find (Fa[x]);}voidUniintXinty) { intPX =find (x); intPY =find (y); if(px==py)return; ElseFA[PX] =py;}intMain () {scanf ("%d%d%d",&n,&a,&B); intMax1 =0; for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); Mp[a[i]]=i; Max1=Max (max1,a[i]); } if(max1>=Max (A, b)) {returnprintf"no\n"),0;} Else{init (); for(intI=1; i<=n;i++) { if(mp[b-A[i]]) Uni (i,mp[b-A[i]]); ElseUni (i,0); if(mp[a-A[i]]) Uni (i,mp[a-A[i]]); ElseUni (i,n+1); } intAF = Find (0); intBF = Find (n+1); if(af==BF) { returnprintf"no\n"),0; } Else{printf ("yes\n"); for(intI=1; i<=n;i++) { if(i!=1) printf (" "); if(Af==find (i)) printf ("0"); Elseprintf"1"); } printf ("\ n"); } } return 0;}
New Ket-2018 Multi-school algorithm fifth field D-Set problem + check set