/ tabris /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:25:21: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[100005]' [-Wformat=]
    scanf("%s",&wokao);
                     ^
/in/foo.cc:59:9: warning: unused variable 'yx' [-Wunused-variable]
     int yx=x,yy=y;
         ^~
# 状态 耗时 内存占用
#1 Accepted 1ms 2.195 MiB
#2 Accepted 1ms 2.297 MiB
#3 Accepted 49ms 2.559 MiB
#4 Accepted 1ms 2.195 MiB
#5 Accepted 10ms 2.316 MiB
#6 Accepted 242ms 4.195 MiB

代码

#include <cstdio>
int now_num,bangpai_num;
int fa[400005],size[400005],newwwwww[400005];
char wokao[100005];

inline int gf(int now){
	if(fa[now]==now)	return now;
	return fa[now]=gf(fa[now]);
}

int main(void){
	int t;
	scanf("%d",&t);
	for(int z=1;z<=t;z++){
		printf("Case #%d:\n",z);
		int n,m;
		scanf("%d%d",&n,&m);
		
		for(int i=1;i<=n;i++)	fa[i]=i,size[i]=1,newwwwww[i]=i;
		now_num=n;
		bangpai_num=n;
		
		for(int i=1;i<=m;i++){
			int x,y;
			scanf("%s",&wokao);
			if(wokao[0]!='q'){
				scanf("%d",&x);
				if(wokao[0]!='r')	scanf("%d",&y);
			}
			
			if(wokao[0]=='q')	printf("%d\n",now_num);
			
			else if(wokao[0]=='f'){
				int yx=x,yy=y;
				x=newwwwww[x];
				y=newwwwww[y];
				int fx=gf(x),fy=gf(y);
				if(fx!=fy){
					if(size[fx]!=size[fy]){
						if(size[fx]>size[fy]){
							printf("%d is winner!\n",yx);
							size[fx]+=size[fy];
							size[fy]=0;
							fa[fy]=fx;
						}
						else{
							printf("%d is winner!\n",yy);
							size[fy]+=size[fx];
							size[fx]=0;
							fa[fx]=fy;
						}
						now_num--;
					}
					else	printf("Either is winner!\n");
				}
			}
			
			else if(wokao[0]=='t'){
				int yx=x,yy=y;
				x=newwwwww[x];
				y=newwwwww[y];
				int fx=gf(x),fy=gf(y);
				if(fx!=fy){
					size[fx]++;
					size[fy]--;
					if(size[fy]==0)	now_num--;
					newwwwww[yy]=++bangpai_num;
					fa[bangpai_num]=fx;
				}
			}
			
			else if(wokao[0]=='r'){
				int woqu=newwwwww[x];
				int fwoqu=gf(woqu);
				
				if(size[fwoqu]!=1){
					newwwwww[x]=++bangpai_num;
					fa[bangpai_num]=bangpai_num;
					size[fwoqu]--;
					size[bangpai_num]=1;
					now_num++;
				}
			}
		}
	}
}

信息

递交者
类型
递交
题目
幼儿园战争
语言
C++
递交时间
2019-10-02 19:22:55
评测时间
2019-10-02 19:22:55
评测机
分数
192
总耗时
307ms
峰值内存
4.195 MiB