QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185744#6634. Central Subsetucup-team870#RE 0ms0kbC++171.2kb2023-09-22 16:04:252023-09-22 16:04:26

Judging History

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

  • [2023-09-22 16:04:26]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-09-22 16:04:25]
  • 提交

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

output:


result: