@[Wow_Goodjob](/space/show?uid=103762) 输出没换行
by かなで @ 2018-06-06 16:38:21
@[かなで](/space/show?uid=100018)
谢谢,但好像不是这个问题,还是WA
by Wow_Goodjob @ 2018-06-06 16:55:23
用cout 输出试一下,我也是这样的。。T_T
by AmlyC @ 2018-07-17 11:03:54
@[zcysky](/space/show?uid=2978) 麻烦看下为什么 printf 输出 wa, cout 输出 ac
by sxb_201 @ 2018-07-21 15:28:11
@[BeyondOI](/space/show?uid=87627) cout也有问题,如下
```cpp
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int N=30000;
int sum[N+1];
int under[N+1];
int f[N+1];
int p;
int cnt;
int ans[1000001];
int getf(int num)
{
if(num==f[num])
{
return num;
}
int t=getf(f[num]);
under[num]+=under[f[num]];
f[num]=t;
return f[num];
}
void merge(int a,int b)
{
int t1=getf(a);
int t2=getf(b);
if(t1!=t2)
{
f[t2]=t1;
under[t2]=sum[t1];
sum[t1]+=sum[t2];
}
}
int main()
{
//freopen("testdata.in","r",stdin);
//freopen("testme.out","w",stdout);
for(int i=1;i<=N;i++)
{
sum[i]=1;
under[i]=0;
f[i]=i;
}
scanf("%d",&p);
for(int i=1;i<=p;i++)
{
char miao;
scanf("%c",&miao);
scanf("%c",&miao);
if(miao=='M')
{
int x,y;
scanf("%d%d",&x,&y);
merge(y,x);
}
else
{
if(miao=='C')
{
int x,y;
scanf("%d%d",&x,&y);
if(getf(f[x])!=getf(f[y]))
{
cout<<"-1"<<endl;
}
else
{
getf(x);
getf(y);
//printf("%d\n",abs(under[x]-under[y]+1));
cout<<abs(under[x]-under[y]+1)<<endl;
}
}
}
}
return 0;
}
```
by Brandon鹏 @ 2018-07-28 09:20:42
@[BeyondOI](/space/show?uid=87627) 和楼主是一样的问题
by Brandon鹏 @ 2018-07-28 09:21:10
@[Brandon鹏](/space/show?uid=86154)
```cpp
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int N=30000;
int sum[N+1];
int under[N+1];
int f[N+1];
int p;
int cnt;
int ans[1000001];
int getf(int num)
{
if(num==f[num])
{
return num;
}
int t=getf(f[num]);
under[num]+=under[f[num]];
f[num]=t;
return f[num];
}
void merge(int a,int b)
{
int t1=getf(a);
int t2=getf(b);
if(t1!=t2)
{
f[t2]=t1;
under[t2]=sum[t1];
sum[t1]+=sum[t2];
}
}
int main()
{
for(int i=1;i<=N;i++)
{
sum[i]=1;
under[i]=0;
f[i]=i;
}
scanf("%d",&p);
for(int i=1;i<=p;i++)
{
char miao;
cin>>miao;//scanf->cin
if(miao=='M')
{
int x,y;
scanf("%d%d",&x,&y);
merge(y,x);
}
else
{
if(miao=='C')
{
int x,y;
scanf("%d%d",&x,&y);
if(getf(f[x])!=getf(f[y]))
{
cout<<"-1"<<endl;
}
else
{
getf(x);
getf(y);
cout<<abs(under[x]-under[y])-1<<endl;//距离要-1
}
}
}
}
return 0;
}
```
by AmlyC @ 2018-07-28 17:41:34
@[Brandon鹏](/space/show?uid=86154)
已AC
by AmlyC @ 2018-07-28 17:42:08