QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135160#6634. Central Subsetwhsyhyyh#WA 0ms13796kbC++141.1kb2023-08-05 12:16:282023-08-05 12:16:31

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 12:16:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:13796kb
  • [2023-08-05 12:16:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int M=1e6+5;
int T;
int n,m,tot;
int hd[M],to[M<<1],nx[M<<1];
void add(int u,int v) {
	nx[++tot]=hd[u];
	to[tot]=v;
	hd[u]=tot;
}
bool vis[M];
bool mk[M]; 
int stk[M],top;
int que[M],L,R;
int dis[M];
int S;
void BFS(int now) {
	L=1,R=0;dis[now]=0;
	que[++R]=now;
	for(int i=1; i<=n; ++i)mk[i]=false,dis[i]=0;
	mk[now]=true;vis[now]=true;
	while(L<=R) {
		int frt=que[L++];
		if(dis[frt]==S)continue;
		for(int i=hd[frt]; i; i=nx[i]) {
			int To=to[i];
			if(mk[To])continue;
			dis[To]=dis[frt]+1;
			que[++R]=To; 
			mk[To]=true;vis[To]=true;
		}
	}
}
int main() {
	cin>>T;
	while(T--) {
		scanf("%d%d",&n,&m);top=tot=0;
		S=sqrt(n);
		if(S*S<n)++S;
		for(int i=1; i<=m; ++i) {
			int u,v;
			scanf("%d%d",&u,&v);
			add(u,v);add(v,u);
		}
		for(int i=1; i<=n; ++i) {
			if(vis[i])continue;
			if(top>S)break;
			stk[++top]=i;BFS(i);
		}
		if(top=-1)puts("-1");
		else {
			printf("%d\n",top);
			for(int i=1; i<=top; ++i)printf("%d ",stk[i]);
			printf("\n");
		}
		for(int i=1; i<=n; ++i)hd[i]=vis[i]=0;
		for(int i=1; i<=m; ++i)to[i]=nx[i]=0;
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 13796kb

input:

2
4 3
1 2
2 3
3 4
6 7
1 2
2 3
3 1
1 4
4 5
5 6
6 4

output:

-1
-1

result:

wrong answer Integer -1 violates the range [1, 2] (test case 1)