QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#216370 | #6634. Central Subset | siddharthjoshi026 | RE | 0ms | 0kb | C++23 | 1.6kb | 2023-10-15 17:46:53 | 2023-10-15 17:46:53 |
answer
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int main(){
long long zz;
cin>>zz;
while(zz--){
long long n,m;
cin>>n>>m;
vector<long long> adj[n];
vector<bool> visited(n,0);
vector<long long> depth(n,0);
set<long long> stt;
long double d = sqrtl(n);
long long bor = d;
if(bor < d) bor++;
for(long long i=0;i<m;i++){
long long x,y;
cin>>x>>y;
x--;y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
bool flag=1;
set<long long> poss;
while(flag){
stt.clear();
poss.clear();
queue<long long> q;
long long y=(rand()*rand())%n;
q.push(y);
depth[y]=0;
stt.insert(y);
while(!q.empty()){
set <long long> nw;
nw.clear();
while(!q.empty()){
long long v=q.front();
q.pop();
visited[v]=1;
if(depth[v]==bor){
poss.insert(v);
nw.insert(v);
}
if(depth[v]==bor+1){
visited[v]=0;
break;
}
for(auto x:adj[v]){
if(!visited[x]){
depth[x]=1+depth[v];
q.push(x);
}
}
}
for(auto x:nw){
visited[x]=0;
}
while(!q.empty()){
q.pop();
}
for(auto x:poss){
if(!visited[x]){
q.push(x);
depth[x]=0;
stt.insert(x);
break;
}
}
}
if(stt.size()<=bor){
for(auto x:poss){
if(!visited[x]&&stt.size()<bor){
stt.insert(x);
}
}
cout<<stt.size()<<'\n';
for(auto x: stt){
cout<<1+x<<' ';
}
cout<<'\n';
flag=0;
}
}
}
return 0;
}
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