QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#216115 | #6634. Central Subset | siddharthjoshi026 | WA | 33ms | 3488kb | C++20 | 1.2kb | 2023-10-15 15:55:36 | 2023-10-15 15:55:37 |
Judging History
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+1];
vector<bool> visited(n+1,0);
vector<long long> depth(n+1,-1);
set<long long> stt;
long long bor;
for(long long i=0;i<=n;i++){
if(i*i>n){
bor=i;
break;
}
}
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);
}
queue<long long> q;
q.push(0);
depth[0]=0;
stt.insert(0);
while(!q.empty()){
long long store=-1;
while(!q.empty()){
long long v=q.front();
q.pop();
visited[v]=1;
if(depth[v]==bor){
store=v;
depth[v]=0;
break;
}
for(auto x:adj[v]){
if(!visited[x]){
depth[x]=1+depth[v];
q.push(x);
}
}
}
while(!q.empty()){
q.pop();
}
if(store==-1){
for(long long i=0;i<n;i++){
if(!visited[i]){
q.push(i);
depth[i]=0;
stt.insert(i);
break;
}
}
}
else{
q.push(store);
stt.insert(store);
}
}
cout<<stt.size()<<'\n';
for(auto x: stt){
cout<<1+x<<' ';
}
cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
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:
2 1 4 2 1 6
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 33ms
memory: 3456kb
input:
10000 15 14 13 12 5 4 9 8 11 12 15 14 10 9 14 13 2 3 2 1 6 5 10 11 3 4 7 6 8 7 6 5 2 1 2 4 4 6 2 3 3 5 10 9 8 3 9 4 5 6 5 10 3 2 5 4 2 7 1 2 4 3 2 1 2 1 2 1 2 1 9 8 9 8 5 4 1 2 6 5 3 4 3 2 7 8 7 6 2 1 1 2 14 13 3 10 5 6 2 9 11 4 2 3 2 1 8 7 13 6 5 4 5 12 6 7 4 3 7 14 16 15 2 3 2 1 6 10 6 9 6 4 9 11 ...
output:
4 1 5 9 13 3 1 5 6 3 1 5 9 1 1 1 1 3 1 5 9 1 1 3 1 5 11 5 1 7 8 9 10 1 1 4 1 6 11 16 3 1 4 5 3 1 5 9 3 1 9 10 1 1 4 1 5 9 13 4 1 5 6 7 1 1 2 1 9 1 1 2 1 4 3 1 4 7 3 1 5 11 3 1 11 12 1 1 4 1 5 9 13 3 1 4 6 3 1 6 13 2 1 3 1 1 5 1 6 11 16 21 5 1 6 7 10 12 3 1 5 11 3 1 1...
result:
wrong answer Integer 5 violates the range [1, 4] (test case 9)