QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135379 | #6634. Central Subset | whsyhyyh | WA | 7ms | 8620kb | C++14 | 1.4kb | 2023-08-05 14:13:15 | 2023-08-05 14:13:17 |
Judging History
answer
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 200010
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
int T,n,m,B,dis[N],st[N],top;
vector<int>G[N];
queue<int>qu;
void bfs(int s) {
qu.push(s),dis[s]=0;
int x;
while(!qu.empty()) {
x=qu.front(),qu.pop();
for(auto v:G[x]) {
if(dis[v]>dis[x]+1) qu.push(v),dis[v]=dis[x]+1;
}
}
}
int main() {
T=rd();
while(T--) {
n=rd(),m=rd();
B=sqrt(n);if(B*B<n)B++;
rep(i,1,n) G[i].clear();
for(int i=1,u,v;i<=m;i++) {
u=rd(),v=rd();
G[u].push_back(v),G[v].push_back(u);
}
rep(i,1,n) dis[i]=inf;
bfs((n+1)/2),st[++top]=(n+1)/2;
while(top<=B) {
int x=0;bool flag=0;
rep(i,1,n) flag|=dis[i]>B;
if(!flag) break;
rep(i,1,n) if(!x||dis[i]==B) {
x=i;
}
bfs(x),st[++top]=x;
}
if(top<=B) {
printf("%d\n",top);
while(top) printf("%d ",st[top]),top--;
puts("");
}
else puts("-1");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8384kb
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 2 1 3
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 8620kb
input:
10000 15 14 13 12 5 4 9 8 11 12 15 14 10 9 14 13 2 3 2 1 6 5 10 11 3 4 7 6 8 7 6 5 2 1 2 4 4 6 2 3 3 5 10 9 8 3 9 4 5 6 5 10 3 2 5 4 2 7 1 2 4 3 2 1 2 1 2 1 2 1 9 8 9 8 5 4 1 2 6 5 3 4 3 2 7 8 7 6 2 1 1 2 14 13 3 10 5 6 2 9 11 4 2 3 2 1 8 7 13 6 5 4 5 12 6 7 4 3 7 14 16 15 2 3 2 1 6 10 6 9 6 4 9 11 ...
output:
3 4 12 8 1 3 1 5 1 1 1 1 3 2 8 5 1 1 2 11 7 3 2 14 8 1 8 4 5 20 15 10 1 4 1 5 2 13 9 1 3 3 4 12 8 1 4 1 1 2 4 5 1 10 1 2 1 4 2 11 7 2 11 9 1 3 3 4 12 8 1 3 3 11 13 8 1 2 1 4 4 6 21 16 11 2 12 7 2 11 7 4 3 12 14 8 1 3 1 3 1 4 2 9 6 3 2 10 11 1 4 3 2 10 6 1 3 ...
result:
wrong answer Integer -1 violates the range [1, 4] (test case 799)