QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134873 | #6634. Central Subset | PhantomThreshold# | WA | 1ms | 3528kb | C++20 | 1.1kb | 2023-08-05 09:36:17 | 2023-08-05 09:36:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void mian()
{
int n,m;
cin>>n>>m;
vector<int> pa(n+5);
function<int(int)> find=[&](int x){return pa[x]?pa[x]=find(pa[x]):x;};
vector<vector<int>> G(n+5);
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
int pu=find(u),pv=find(v);
if(pu!=pv)
{
G[u].push_back(v),G[v].push_back(u);
pa[pv]=pu;
}
}
vector<int> dep(n+5);
function<void(int)> dfs=[&](int u)
{
for(auto v:G[u])
{
if(not dep[v])
{
dep[v]=dep[u]+1;
dfs(v);
}
}
};
dep[1]=1;
dfs(1);
int s=sqrt(n);
while(s*s<n)s++;
vector<vector<int>> dg(s+5);
for(int i=1;i<=n;i++)
{
dg[dep[i]%n].push_back(i);
}
for(int i=0;i<s;i++)
{
if((int)dg[i].size()==0)
{
cout<<1<<"\n";
cout<<1<<"\n";
return;
}
if((int)dg[i].size()<=s)
{
cout<<dg[i].size()<<"\n";
for(auto x:dg[i])
cout<<x<<' ';
cout<<"\n";
return;
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
mian();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3528kb
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 4 1 1
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)