QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127567 | #6634. Central Subset | Vriance | WA | 9ms | 9740kb | C++14 | 1.5kb | 2023-07-19 19:52:01 | 2023-07-19 19:52:08 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn=200005;
const int INF=0x7f7f7f7f;
inline int read(){
int x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')w=-1;
for(;isdigit(c);x=(x<<3)+(x<<1)+c-'0',c=getchar());
return x*w;
}
inline ll readll(){
ll x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')w=-1;
for(;isdigit(c);x=(x<<3)+(x<<1)+c-'0',c=getchar());
return x*w;
}
int n,m,k;
vector<int>vct[maxn],st;
int dep[maxn];
int fa[maxn],vis[maxn];
int dfs(int u,int f){
dep[u]=dep[f]+1;
fa[u]=f;
int mx=dep[u];
for(int i=0;i<vct[u].size();i++){
int v=vct[u][i];
if(v==f||fa[v])continue;
int a=dfs(v,u);
mx=max(mx,a);
}
if(mx-dep[u]==k){
vis[u]=1;
return 0;
}
return mx;
}
int main(){
int t=read();
for(;t--;){
n=read(),m=read();
k=sqrt(n)*sqrt(n)<n?(sqrt(n)+1):sqrt(n);
for(int i=1;i<=m;i++){
int u=read(),v=read();
vct[u].push_back(v);
vct[v].push_back(u);
}
int mx=dfs(1,0);
if(st.size()<k)vis[1]=1;
for(int i=1;i<=n;i++){
if(vis[i])st.push_back(i);
}
int s=st.size();
int sz=min(s,k);
printf("%d\n",sz);
for(int i=0;i<sz;i++){
printf("%d ",st[i]);
}
printf("\n");
st.clear();
for(int i=1;i<=n;i++)vct[i].clear(),vis[i]=dep[i]=fa[i]=0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9100kb
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 2 2 1 2
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 9ms
memory: 9740kb
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 1 4 8 2 1 2 2 1 3 1 1 1 1 3 1 2 6 1 1 3 1 2 5 3 1 3 10 1 1 4 1 6 11 16 2 1 2 2 1 3 3 1 2 8 1 1 3 1 4 8 2 1 2 1 1 2 1 2 1 1 2 1 2 2 1 2 3 1 2 5 3 1 2 8 1 1 3 1 4 8 2 1 2 2 1 5 1 1 1 1 4 1 2 7 12 2 1 3 3 1 2 5 3 1 4 7 1 1 2 1 4 2 1 3 2 1 4 4 1 2 9 10 1 1 3 1 5...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)