/ tabris /

记录详情

Runtime Error


  
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 1.73 MiB
#2 Wrong Answer 3ms 1.812 MiB
#3 Runtime Error 22ms 10.004 MiB
#4 Wrong Answer 2ms 1.719 MiB
#5 Runtime Error 21ms 9.953 MiB
#6 Runtime Error 5ms 2.465 MiB

代码

#include <iostream>
#include <cstdio>
#include <cstring>
#define next nx
using namespace std;
const int maxn=100005;
int fa[maxn],size[maxn],mapped[2*maxn],hui[2*maxn];
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int n,m,x,y,fx,fy,cnt,next;
int getfa(int x){
	if(fa[x]==x)return x;
	return fa[x]=getfa(fa[x]);
}
inline void gai(int yuan,int now){
	mapped[yuan]=now;
	hui[now]=yuan;
}
int main(){
	int t;
	t=read();
	for(int k=1;k<=t;k++){
		printf("Case #%d\n",k);
		memset(mapped,0,sizeof(mapped));
		memset(hui,0,sizeof(hui));
		n=read();m=read();
		for(int i=1;i<=n;i++){fa[i]=i;size[i]=1;}
		cnt=n+1;
		int shu_bangpai=n;
		for(int i=1;i<=m;i++){
			string s;
			cin>>s;
			if(s=="query")printf("%d\n",shu_bangpai);
			if(s=="fight"){
				bool flag1=0,flag2=0;
				x=read();y=read();
				if(mapped[x]){
					x=mapped[x];
					flag1=1;
				}
				if(mapped[y]){
					y=mapped[y];
					flag2=1;
				}
				fx=getfa(x);fy=getfa(y);
				//cout<<x<<' '<<y<<' '<<fx<<' '<<fy<<endl;
				if(fx==fy)continue;
				if(size[fx]==size[fy]){
					printf("Either is winner!\n");
					continue;
				}
				shu_bangpai--;
				if(size[fx]>size[fy]){
					size[fx]+=size[fy];
					size[fy]=0;
					fa[fy]=fx;
					printf("%d is winner!\n",flag1==0?x:hui[x]);
				}
				if(size[fx]<size[fy]){
					size[fy]+=size[fx];
					size[fx]=0;
					fa[fx]=fy;
					printf("%d is winner!\n",flag2==0?y:hui[y]);
				}
			}
			if(s=="tempt"){//x诱惑y 
				x=read();y=read();
				if(mapped[x])x=mapped[x];
				if(mapped[y])y=mapped[y];
				fx=getfa(x);fy=getfa(y);
				cnt++;
				next=cnt;
				if(fx==fy)continue;
				gai(y,next);
				shu_bangpai--;
				fa[next]=fx;
				size[fx]++;
				size[fy]--;
			}
			if(s=="revolt"){//反叛,传位。 
				x=read();fx=getfa(x);
				if(mapped[x])x=mapped[x];
				shu_bangpai++;
				cnt++;
				next=cnt;
				gai(x,next);
				fa[x]=x;
				size[x]++;
				size[fx]--;	
			}
		}
	}
}

信息

递交者
类型
递交
题目
幼儿园战争
语言
C++
递交时间
2019-10-02 16:03:25
评测时间
2019-10-02 16:03:25
评测机
分数
0
总耗时
57ms
峰值内存
10.004 MiB