QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205216 | #6634. Central Subset | Geospiza# | WA | 13ms | 23808kb | C++20 | 1.7kb | 2023-10-07 15:12:14 | 2023-10-07 15:12:15 |
Judging History
answer
//#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#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 ma;
void dfss(ll u,ll pre,ll now, vector<ll>&ans)
{
if(now==ma-1){
ll flag=0;
for(auto v:vcc[u]){
if(v!=pre){
if(flag==0){
flag=1;
ans.push_back(v);
dfss(v,u,0,ans);
}
else{
dfss(v,u,2,ans);
}
}
}
}
else{
for(auto v:vcc[u])
if(v!=pre)
dfss(v,u,now+1,ans);
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int T=1;
cin>>T;
while(T--)
{
cin>>n>>m;
ma=sqrtl(n-1.0)+1;
vector<ll>ans;
rep(i,1,n)
{
vis[i]=0;
vec[i].clear(),vcc[i].clear();
}
rep(i,1,m)
{
ll u,v;
cin>>u>>v;
vec[u].pb(v);
vec[v].pb(u);
}
if(n==1){
cout<<"1\n1\n";
continue;
}
dfs(1,0);
dfss(1,0,ma-1,ans);
cout<<ans.size()<<"\n";
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
}
/*
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
1
1 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 23688kb
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 2 4 2 2 5
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 23808kb
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 2 6 10 14 1 2 2 2 6 1 2 1 2 3 2 5 8 1 2 2 2 6 3 2 10 16 1 2 4 2 7 12 17 2 2 6 2 2 10 2 2 13 1 2 4 2 6 10 14 1 2 1 2 2 2 9 1 2 2 2 4 2 2 6 2 2 6 2 2 13 1 2 4 2 6 10 14 1 2 2 2 6 1 2 1 2 4 2 7 12 17 3 2 11 13 2 2 6 3 2 11 10 1 2 2 2 5 3 2 6 7 2 2 6 3 2 10 9 1 2...
result:
wrong answer Integer 5 violates the range [1, 4] (test case 192)