QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185744 | #6634. Central Subset | ucup-team870# | RE | 0ms | 0kb | C++17 | 1.2kb | 2023-09-22 16:04:25 | 2023-09-22 16:04:26 |
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=2e5+5;
int fa[N],dep[N];
vector<int>tu[N],ans[N];
int fd(int x){
if(x==fa[x])return x;
return fa[x]=fd(fa[x]);
}
void dfs(int now,int pre){
dep[now]=dep[pre]+1;
for(int son:tu[now]){
if(son==pre)continue;
dfs(son,now);
}
}
void slv(){
int n,m;cin>>n>>m;
ans[0].clear();
rep(i,1,n){
fa[i]=i; tu[i].clear(); ans[i].clear();
}
rep(i,1,m){
int u,v;cin>>u>>v;
int uu=fd(uu),vv=fd(vv);
if(uu!=vv){
fa[uu]=vv; tu[u].push_back(v); tu[v].push_back(u);
}
}
dfs(1,0);
int sn=sqrt(n);
while(sn*sn<n)++sn;
rep(i,1,n){
ans[dep[i]%sn].push_back(i);
}
rep(i,0,sn-1){
if(ans[i].size()<=sn){
cout<<ans[i].size()<<'\n';
for(auto v:ans[i])cout<<v<<' '; cout<<'\n';return;
}
}
assert(0);
}
int main() {
IOS
int T;cin>>T;
while(T--)slv();
return 0;
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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