愤怒

考场想到正解

然后觉得我的“正解”和正解差不多 一样的效果

被忽略的与正解的不同也想到了

然而 我懒得再写

于是快乐10分

气坏了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#define rint register int
using std::sort;
using std::map;
//using std::cout;
//using std::endl;
template <class T>inline void read(T &X)
{
X=;int W=;char ch=;
while(!isdigit(ch))W|=ch=='-',ch=getchar();
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
X=W?-X:X;return;
}
int n,cnt=,ans=;
long long sta[],end[],xors=,xore=,sta2[],end2[],fa[];
bool boo(true);
long long find(long long x){return fa[x]==x?x:fa[x]=find(fa[x]);}
map<int,int>num;
int main()
{
// freopen("duliu.in","r",stdin);
// freopen("duliu.out","w",stdout);
read(n);
for(rint i=;i<=n;++i)
read(sta[i]),sta2[i]=sta[i],xors^=sta[i];
sta[n+]=xors;sta2[n+]=xors;
for(rint i=;i<=n;++i)
{
read(end[i]),end2[i]=end[i];
xore^=end[i];
if(xors==end[i])boo=false;
}
end[n+]=xore;end2[n+]=xore;
++n;
sort(sta2+,sta2+n+);
sort(end2+,end2+n+); for(rint i=;i<=n;++i)
{
if(sta2[i]!=end2[i]){printf("-1\n");return ;}
}
cnt=;
for (int i=;i<=n;i++)
{
if (sta[i]!=end[i]||i==n)
{
if (i<n) ans++;
if (!num[sta[i]]) cnt++,num[sta[i]]=cnt;
if (!num[end[i]]) cnt++,num[end[i]]=cnt;
}
}
if (ans==)
{
printf("0\n");
return ;
}
for (int i=;i<=cnt;i++) fa[i]=i;
for (int i=;i<=n;i++) if (sta[i]!=end[i]) fa[find(num[sta[i]])]=find(num[end[i]]);
for (int i=;i<=cnt;i++) if (fa[i]==i) ans++;
printf("%d\n",ans-);
return ;
}

最新文章

  1. webrtc中APM(AudioProcessing module)的使用
  2. C#输出文本树形层次,前或者后自定义空格位数
  3. 利用history实现无刷新跳转界面
  4. 轻量级Lua IDE ZeroBrane Studio 的使用技巧和汉化
  5. 炉石复盘 宇宙法vs复活牧 [20161130]
  6. Sql助手
  7. 【python之路7】python基本数据类型(一)
  8. 使用SQLCipher加密数据库
  9. Windows下与Linux下编写socket程序的区别 《转载》
  10. PredictionIO+Universal Recommender快速开发部署推荐引擎的问题总结(2)
  11. 作业五:RE 模块模拟计算器
  12. [UWP 自定义控件]了解模板化控件(1):基础知识
  13. AD 16 下绘图的几个技巧
  14. C#:单元测试(VS2015)
  15. 小程序开发 绑定自定义数据data- 及JS获取
  16. mongodb 远程访问配置
  17. 解题:POI 2014 Ant colony
  18. December 11th 2016 Week 51st Sunday
  19. kvm虚拟主机安装速度很慢
  20. JS学习之函数的属性和方法

热门文章

  1. BSC软件交流-BS
  2. UML-类图-箭头
  3. ubuntu编译caffe遇到的问题及解决方案
  4. _\_call\_\_
  5. Python 爬虫 爬取图片入门
  6. 34)static 静态成员和静态成员函数
  7. 图像的手绘效果(Python)
  8. php对比二个不同的二维数组
  9. 吴裕雄--天生自然python Google深度学习框架:TensorFlow实现神经网络
  10. WOW.js——在页面滚动时展现动感的元素动画效果