/ tabris /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Accepted 3ms 4.82 MiB
#2 Wrong Answer 5ms 4.82 MiB
#3 Wrong Answer 44ms 4.848 MiB
#4 Accepted 3ms 4.871 MiB
#5 Wrong Answer 12ms 4.816 MiB
#6 Wrong Answer 184ms 4.816 MiB

代码

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

inline int read() {
    int x=0,f=1;
    char cr=getchar();
    while (cr>'9' || cr<'0') {
        if (cr=='-') f=-1;
        cr=getchar();
    }
    while (cr>='0' && cr<='9') {
        x=(x<<3)+(x<<1)+cr-'0';
        cr=getchar();
    }
    return x*f;
}

const int maxn=100005;

char a[10];

int real[maxn<<2],fa[maxn<<2],size[maxn<<2];

inline int getf(int k) {
    return fa[k]==k ? k : fa[k]=getf(fa[k]);
}

inline void file() {
	freopen("game.in","r",stdin);
    freopen("game.out","w",stdout);
}

inline void _remove() {
	memset(real,0,sizeof(real));
	memset(fa,0,sizeof(fa));
	memset(size,0,sizeof(size));
}

int main() {
	//file();
	int t=read();
	for (int cao=1;cao<=t;cao++) {
		printf("Case #%d:\n",cao);
		_remove();
    	int n=read(),m=read();
    	for (int i=1;i<=n;i++) real[i]=i,fa[i]=i,size[i]=1;
    	int tot=n,cnt=n;
    	for (int i=1;i<=m;i++) {
        	scanf("%s",a);
        	if (a[0]=='q') printf("%d\n",tot);
        	if (a[0]=='f') {
            	int x=read(),y=read();
            	int fx=getf(real[x]),fy=getf(real[y]);
            	if (fx==fy) continue;
            	if (size[fx]>size[fy]) {
            	    size[fx]+=size[fy];
            	    fa[fy]=fx;
            	    tot--;
            	    printf("%d is winner!\n",x);
            	}
            	else if (size[fx]<size[fy]) {
                	size[fy]+=size[fx];
                	fa[fx]=fy;
                	tot--;
                	printf("%d is winner!\n",y);
            	}
            	else if (size[fx]==size[fy]) printf("Either is winner!\n");
        	}
        	if (a[0]=='t') {
            	int x=read(),y=read();
            	int fx=getf(real[x]),fy=getf(real[y]);
            	if (fx!=fy) {
            	    real[y]=++cnt;
       	    	    fa[real[y]]=real[x];
        	        size[fx]++;
       		        if (size[fy]==1) tot--;
       		    }
        	}
        	if (a[0]=='r') {
        	    int x=read(),fx=getf(real[x]);
        	    if (size[fx]==1) continue;
				size[fx]--;
        	    real[x]=++cnt;
        	    fa[real[x]]=real[x];
        	    size[real[x]]=1;
       		    tot++;
       		}
    	}
	}
}

信息

递交者
类型
递交
题目
幼儿园战争
语言
C++
递交时间
2019-10-02 16:04:32
评测时间
2019-10-02 16:04:32
评测机
分数
64
总耗时
252ms
峰值内存
4.871 MiB