P1196 提示too short on line 1 求助
查看原帖
P1196 提示too short on line 1 求助
674793
luoguhandongheng楼主2022/9/2 12:31

点进来的大佬,蒟蒻感激不尽! P1196 [NOI2002] 银河英雄传说 我自己下了数据和答案对了一模一样,为什么会有too short on line 1这个提醒?? 题目 评测记录

#include <bits/stdc++.h>
using namespace std;
int f[30005],T,num[30005],front[30005];
const int N=30000;
void inxt(){
	for(int i=1;i<=N;i++){
		f[i]=i;
		num[i]=1;
		front[i]=0;
	} 
}
int getf(int x){
	int fn=x;
	if(f[x]!=x)	fn=getf(f[x]);
	front[x]+=front[f[x]];
	f[x]=fn;
	return f[x];
} 
void gether(int x,int y){
	x=getf(x);
	y=getf(y);
	if(x!=y){
		f[x]=y;
		front[x]=num[y];
		num[y]+=num[x];
		num[x]=0;
	}
}
int main(){
	scanf("%d",&T);
	inxt();
	for(int i=1;i<=T;i++){
		getchar();
		int x,y;
		char c=getchar();
		scanf("%d%d",&x,&y);
		if(c=='M')
			gether(x,y);
		else if(c=='C'){
			if(getf(x)!=getf(y))
				printf("-1\n");
			else
				printf("%d\n",abs(front[x]-front[y])-1); 
		}
	}
	return 0;
}
2022/9/2 12:31
加载中...