QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205163 | #6634. Central Subset | Geospiza# | RE | 0ms | 0kb | C++20 | 1.4kb | 2023-10-07 15:02:12 | 2023-10-07 15:02:13 |
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
*/
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