银河英雄传说
来源:互联网 发布:人口老龄化数据 编辑:程序博客网 时间:2024/04/28 06:55
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int t;int q[99999];int h[99999];int f[99999];int find(int x){ if(f[x]==x)return x; int fx=find(f[x]); q[x]=q[x]+q[f[x]]; return f[x]=fx; //if(f[x]!=x) f[x]=find(f[x]);// q[x]=q[x]+q[f[x]]; //return f[x];}void work(int b,int c){ int fx=find(b); int fy=find(c); //q[fx]=fy; q[fx]=h[fy]; h[fy]+=h[fx]; //q[c]=q[b]+h[b]+q[c]; //h[b]=h[b]+h[c]; f[fx]=fy;}int main(){ scanf("%d",&t); for(int i=1;i<=30000;i++) f[i]=i,h[i]=1; for(int i=1;i<=t;i++) { char a; int b,c; cin>>a>>b>>c; if(a=='M') { work(b,c); } if(a=='C') { if(find(b)==find(c)) printf("%d\n",abs(q[b]-q[c])-1); else printf("-1\n"); } } return 0;}
这个题abs外减1
并且还要q+上去
1 0
- TYVJ 银河英雄传说
- 【noi2002】银河英雄传说
- Noi2002银河英雄传说
- 【NOI2002】银河英雄传说
- 【codevs1540】 银河英雄传说
- 银河英雄传说
- 【u010】银河英雄传说
- 1540 银河英雄传说
- P1196 银河英雄传说
- [P1196]银河英雄传说
- 银河英雄传说
- NOI2002 银河英雄传说
- NOI2002 银河英雄传说
- 银河英雄传说
- NOI2002-银河英雄传说
- [codevs1540]银河英雄传说
- 【NOI2002】银河英雄传说
- Codevs1540银河英雄传说
- Java命令执行jar包:java -jar xxx.jar
- JavaEE 学习过程中遇到的问题
- 微信支付的模式及申请流程介绍
- mybatis mapper.xml 区间查询条件
- 请求返回json串和文件下载实例
- 银河英雄传说
- Ubuntu安装eclipse,并创建桌面快捷方式
- FE
- ADB不识别device not found
- NTC33 The Spirit Of Old School Crazy 7 Slot Game
- [iOS]APP打包上传后在构建版本中不显示
- Spring-mvc的jdbc
- Hibernate 运行报错:Error calling Driver#connect
- unity OpenCV生成mask 进行抠图