QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205318 | #6634. Central Subset | Geospiza# | WA | 15ms | 25748kb | C++20 | 1.4kb | 2023-10-07 15:31:18 | 2023-10-07 15:31:18 |
Judging History
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];
ll B;
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);
}
vector<ll>v;
ll dep[N],vc[N];
ll dfss(ll u,ll pre)
{
ll dp=0;
for(auto v:vcc[u])if(v!=pre)
{
dp=max(dp,dfss(v,u)+1);
}
if(dp==B)
{
v.pb(u);
return -1;
}
return dp;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int T=1;
cin>>T;
while(T--)
{
cin>>n>>m;
v.clear();
rep(i,1,n)
{
vis[i]=vc[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);
}
dfs(1,0);
B=(ll)sqrt(n-1.0)+1;
dfss(1,0);
if(v.empty())v.pb(1);
assert(v.size()<=B);
cout<<v.size()<<"\n";
for(auto x:v)cout<<x<<" ";
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 24852kb
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:
1 2 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 25748kb
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:
3 11 6 1 1 1 1 2 1 1 1 1 2 6 2 1 1 1 4 2 10 3 1 1 3 15 9 3 1 3 1 2 1 5 1 1 3 11 6 1 1 1 1 1 1 2 1 1 1 2 1 3 1 4 2 5 1 1 1 3 11 6 1 1 1 2 5 1 1 1 1 1 3 16 10 4 1 2 1 4 2 7 4 1 1 1 3 1 2 1 3 3 7 6 1 1 1 2 8 3 1 1 1 3 1 2 1 1 2 6 1 1 3 1 3 2 5 1 1 1 3 1...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 402)