/ tabris /

记录详情

Runtime Error


  
# 状态 耗时 内存占用
#1 Wrong Answer 1ms 416.0 KiB
#2 Wrong Answer 1ms 952.0 KiB
#3 Wrong Answer 120ms 700.0 KiB
#4 Wrong Answer 1ms 220.0 KiB
#5 Wrong Answer 32ms 544.0 KiB
#6 Runtime Error 7ms 1.332 MiB

代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,fa[100005],c=1,cnt,T,num[100005],r[100005],ans;
inline void init(){
	ans=n; cnt=n;
	for(int i=1;i<=n;++i) r[i]=i,fa[i]=i,num[i]=1;
}
inline int find(int x){
	if(fa[x]==x) return x;
	else return fa[x]=find(fa[x]);
}
int main(){
	//freopen("game.in","w",stdin);
	//freopen("game.out","r",stdout);
	scanf("%d",&T);
	while(T--){
		printf("Case #%d\n",c);
		scanf("%d%d",&n,&m);
		init();
		while(m--){
			string s; int x,y;
			cin>>s;
			if(s=="query"){
				printf("%d\n",ans);
			}
			if(s=="fight"){
				scanf("%d%d",&x,&y);
				int xx=find(r[x]),yy=find(r[y]);
				if(xx==yy) continue;
				else if(num[xx]<num[yy]){
					printf("%d is winner\n",y);
					fa[xx]=yy;
					num[yy]+=num[xx];
					ans--;
				}
				else if(num[xx]>num[yy]){
					printf("%d is winner!\n",x);
					fa[yy]=xx;
					num[xx]+=num[yy];
					ans--;
				}
				else printf("Either is winner!\n");
			}
			if(s=="tempt"){
				scanf("%d%d",&x,&y);
				int xx=find(r[x]),yy=find(r[y]);
				if(xx!=yy){
					if(num[yy]==1) ans--;
					r[y]=++cnt;
					fa[r[y]]=r[x];
					num[xx]++; num[yy]--;
				}
			}
			if(s=="revolt"){
				scanf("%d",&x);
				int xx=find(r[x]);
				if(num[xx]==1) continue;
				num[xx]--;
				r[x]=++cnt;
				fa[r[x]]=r[x];
				num[r[x]]=1;
				ans++;
			}
		}
	}
}

信息

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