QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205348 | #6634. Central Subset | Geospiza# | WA | 25ms | 25892kb | C++20 | 1.4kb | 2023-10-07 15:37:30 | 2023-10-07 15:37:31 |
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=1;
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: 24972kb
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 3 1 2 4 1
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 15ms
memory: 25096kb
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 12 8 4 1 2 1 3 1 1 1 1 3 7 4 1 1 1 2 5 2 2 12 4 1 1 4 16 11 6 1 2 4 2 1 3 2 8 2 1 1 3 12 8 4 1 2 1 1 2 4 2 1 1 2 3 1 2 4 2 2 5 2 2 8 2 1 1 3 12 8 4 1 2 2 6 3 1 2 1 1 4 17 12 7 2 1 3 2 5 2 3 10 6 1 1 1 2 4 1 1 3 2 4 1 3 10 9 2 1 1 3 9 5 1 1 2 2 4 1 2 3 1 ...
result:
ok correct (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 25ms
memory: 25892kb
input:
100 2000 1999 529 528 885 884 1221 1222 375 374 245 244 758 757 711 710 1521 1522 1875 1874 749 750 823 822 1959 1958 1767 1766 155 154 631 632 825 824 1330 1331 457 456 1344 1343 1817 1818 413 414 582 583 1828 1827 1335 1336 654 655 162 161 1668 1667 1966 1967 1472 1471 1185 1184 518 517 1509 1510 ...
output:
44 1956 1911 1866 1821 1776 1731 1686 1641 1596 1551 1506 1461 1416 1371 1326 1281 1236 1191 1146 1101 1056 1011 966 921 876 831 786 741 696 651 606 561 516 471 426 381 336 291 246 201 156 111 66 21 1 1 22 957 913 869 825 781 737 693 649 605 561 517 473 429 385 341 297 253 209 165 121 77 33 5 106...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 74)