QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205163#6634. Central SubsetGeospiza#RE 0ms0kbC++201.4kb2023-10-07 15:02:122023-10-07 15:02:13

Judging History

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

  • [2023-10-07 15:02:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-07 15:02:12]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;++i)
typedef pair<ll,ll> pll;
const ll N=4e5+5;
vector<ll>vec[N],vcc[N];
ll t,n,m,k,tt,tp;
ll vis[N];
void dfs(ll u,ll pre)
{
    if(vis[u])return ;
    vis[u]=1;
    if(pre!=0){
    vcc[u].pb(pre);
    vcc[pre].pb(u);}
    for(auto v:vec[u])if(v!=pre)dfs(v,u);
}
ll dep[N];
vector<ll>vc[N];
void dfss(ll u,ll pre)
{
    dep[u]=dep[pre]+1;
    vc[dep[u]].pb(u);
    for(auto v:vcc[u])if(v!=pre)dfss(v,u);
}
int	 main(){
	//dabiao();
    ios::sync_with_stdio(0); cin.tie(0);
	int T=1;
	cin>>T;
	while(T--)
    {
        cin>>n>>m;
        rep(i,1,n)
        {
            vis[i]=0;
            vc[i].clear();
            vec[i].clear(),vcc[i].clear();
        }
        rep(i,1,m)
        {
            ll u,v;
            cin>>u>>v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(1,0);
        dfss(1,0);
        ll B=(ll)sqrt(n-1.0)+1,bs=B-1;
        vector<ll>v;
        while(B<=n)
        {
            for(auto x:vc[B])v.pb(x);
            B+=bs;
        }
        assert(v.size()<=(ll)sqrt(n-1.0)+1);
        cout<<v.size()<<"\n";
        for(auto x:v)cout<<x<<" ";
        cout<<"\n";
    }
}
/*
4
1 1 1 1
*/


详细

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: