/ tabris /

记录详情

Time Exceeded

/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 Wrong Answer 5ms 512.0 KiB
#2 Wrong Answer 1ms 456.0 KiB
#3 Time Exceeded ≥1000ms ≥572.0 KiB
#4 Accepted 2ms 268.0 KiB
#5 Time Exceeded ≥1000ms ≥396.0 KiB
#6 Time Exceeded ≥1000ms ≥1.336 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++;
				}
			}
			
			for(int i=1;i<=bangpai_num;i++)	printf("%d ",gf(i));
			printf("\n");
		}
	}
}

信息

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