版本比较
POJ1417 True Liars(并查集)
正文
增加 7 行删除 7 行
48 行未改动49505152535354555657575859606123 行未改动858687888989909192929394949596979798991001018 行未改动1101111121131141141151161171184 行未改动48 行未改动 if(fa[x]!=x){ int t=getfa(fa[x]); dis[x]^=dis[fa[x]]; fa[x]=t; } } return fa[x];}int n,p,q,tot=0;int A[M][2];//表示一个集合中的两种元素的个数 int A[M][2];//表示一个集合中的两种元素的个数int be[M],dp[2][M],pa[M][M];int ans[M],acnt=0;int main(){ while(~scanf("%d%d%d",&n,&p,&q)&&(n||p||q)){23 行未改动 if(getfa(i)==i){ tot++; be[i]=tot; } } } for(int i=1;i<=p+q;i++){ A[be[getfa(i)]][dis[i]]++; } } dp[0][0]=1; for(int i=1;i<=tot;i++){//选了若干集合 for(int i=1;i<=tot;i++){//选了若干集合 int cur=(i&1); clr(dp[cur],0); for(int j=0;j<=p;j++){//挑出了一些点作为好人 for(int j=0;j<=p;j++){//挑出了一些点作为好人 if(j>=A[i][0])dp[cur][j]+=dp[!cur][j-A[i][0]]; if(j>=A[i][1])dp[cur][j]+=dp[!cur][j-A[i][1]]; if(j>=A[i][0]&&dp[!cur][j-A[i][0]]==1)pa[i][j]=0; else if(j>=A[i][1]&&dp[!cur][j-A[i][1]]==1)pa[i][j]=1;8 行未改动 for(int r=1;r<=p+q;r++){ if(be[getfa(r)]==i&&dis[r]==k)ans[++acnt]=r; } j-=A[i][k];i--; } } sort(ans+1,ans+acnt+1); for(i=1;i<=acnt;i++) printf("%d\n",ans[i]); puts("end");4 行未改动