QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134882 | #6634. Central Subset | SolitaryDream# | WA | 8ms | 9860kb | C++20 | 1.1kb | 2023-08-05 09:42:44 | 2023-08-05 09:42:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1e3+7;
int T,n,m,L;
vector<int>g[N];
int vis[N],d[N];
vector<int>ans;
void dfs(int x)
{
d[x]=1e9;
for(auto v:g[x])
{
if(vis[v])
continue;
vis[v]=1;
dfs(v);
d[x]=min(d[x],d[v]+1);
}
if(d[x]==1e9)
d[x]=0;
if(d[x]==L)
ans.push_back(x),d[x]=0;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
L=0;
while(L*L<n)
L++;
for(int i=1;i<=n;i++)
vis[i]=0,g[i].clear();
ans.clear();
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
vis[1]=1;
dfs(1);
if(!ans.size()||ans.back()!=1)
ans.push_back(1);
printf("%d\n",(int)ans.size());
for(int i=0;i<ans.size();i++)
printf("%d%c",ans[i]," \n"[i+1==ans.size()]);
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8380kb
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:
2 2 1 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 8ms
memory: 9860kb
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:
4 11 7 3 1 1 1 1 1 1 1 1 1 3 6 3 1 1 1 1 1 1 1 1 1 4 15 10 5 1 1 1 1 1 1 1 1 1 4 11 7 3 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 4 11 7 3 1 1 1 1 1 1 1 1 1 4 16 11 6 1 1 1 1 1 2 7 1 1 1 2 3 1 2 2 1 1 1 1 1 1 1 3 8 4 1 1 1 1 1 2 2 1 1 1 3 6 2 1 1 1 1 1 2 5 1 1 1 4 13 8 3 1 1 1 1 1 1 1 1 1 4 12 8 4 1 1...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 3)