/ tabris /

记录详情

Wrong Answer

/in/foo.cc: In function 'int change(int)':
/in/foo.cc:19:19: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if(fa[i]=x&&i!=x){
                   ^
# 状态 耗时 内存占用
#1 Wrong Answer 1ms 484.0 KiB
#2 Wrong Answer 1ms 836.0 KiB
#3 Wrong Answer 115ms 484.0 KiB
#4 Wrong Answer 1ms 220.0 KiB
#5 Wrong Answer 32ms 348.0 KiB
#6 Wrong Answer 532ms 980.0 KiB

代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,fa[100005],c=1,T,num[100005],ans;
inline void init(){
	ans=n;
	for(int i=1;i<=n;++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]);
}
inline int change(int x){
	int t=0;
	for(int i=1;i<=n;++i){
		if(fa[i]=x&&i!=x){
			if(!t)t=i;
			else fa[i]=t;
		}
	}
	return t;
}
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(x),yy=find(y);
				if(xx==yy) continue;
				else if(num[xx]<num[yy]){
					printf("%d is winner\n",y);
					fa[xx]=yy;
					num[yy]+=num[xx];
					num[xx]=0;
					ans--;
				}
				else if(num[xx]>num[yy]){
					printf("%d is winner!\n",x);
					fa[yy]=xx;
					num[xx]+=num[yy];
					num[yy]=0;
					ans--;
				}
				else printf("Either is winner!\n");
			}
			if(s=="tempt"){
				scanf("%d%d",&x,&y);
				int xx=find(x),yy=find(y);
				if(y==yy){
					if(num[yy]==1){
						num[yy]--;
						ans--;
						fa[y]=xx;
						num[xx]++;
					}
					else{
						num[change(y)]=num[y]-1;
						num[yy]=0;
						fa[y]=xx;
						num[xx]++;
					}
				}
				else{
					num[xx]++; num[yy]--;
					fa[y]=xx;
				}
			}
			if(s=="revolt"){
				scanf("%d",&x);
				int xx=find(x);
				if(xx==x){
					if(num[x]==1) continue;
					else{
						num[change(x)]=num[x]-1;
						num[x]=1;
						ans++;
					}
				}
				num[xx]--;
				fa[x]=x;
				num[x]=1;
				ans++;
			}
		}
	}
}

信息

递交者
类型
递交
题目
幼儿园战争
语言
C++
递交时间
2019-10-02 16:04:38
评测时间
2019-10-02 16:04:38
评测机
分数
0
总耗时
685ms
峰值内存
980.0 KiB