QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127574 | #6634. Central Subset | 45645A | WA | 4ms | 9736kb | C++14 | 1.7kb | 2023-07-19 19:56:34 | 2023-07-19 19:56:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
char ch;
while((ch=getchar())<'0'||ch>'9');
int res=ch-'0';
while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0';
return res;
}
const int N=200100;
struct Edge{
int nxt,to;
}e[N<<1];
int h[N],e_num;
void add(int from,int to)
{
e[++e_num].nxt=h[from];
e[e_num].to=to;
h[from]=e_num;
}
int n,K;
struct BCJ{
int f[N];
void pre()
{
for(int i=1;i<=n;i++)
f[i]=i;
}
int find(int x){ return f[x]==x?x:(f[x]=find(f[x])); }
bool mrge(int x,int y)
{
x=find(x),y=find(y);
if(x==y) return 0;
f[x]=y;
return 1;
}
}B;
int res[N],ans,vis[N];
int dep[N];
struct node{
int dep,u;
node(int a=0,int b=0){
u=a,dep=b;
}
};
bool operator<(node a,node b){ return a.dep<b.dep; }
priority_queue<node>Q;
int stk[N],top,fa[N];
void dfs(int u)
{
stk[++top]=u;Q.push(node(u,dep[u]));
if(top>K) fa[u]=stk[top-K];
else fa[u]=1;
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].to;
if(dep[v]) continue;
dep[v]=dep[u]+1;
dfs(v);
}
top--;
}
void dfs_vis(int u)
{
vis[u]=1;
for(int i=h[u];i;i=e[i].nxt)
{
int v=e[i].to;
if(vis[v]||dep[v]<dep[u]) continue;
dfs_vis(v);
}
}
int main()
{
int T=read();
while(T--)
{
n=read();int m=read();
B.pre();
e_num=0;
ans=0;
for(int i=1;i<=n;i++) vis[i]=h[i]=0;
for(int i=1;i<=m;i++)
{
int u=read(),v=read();
if(B.mrge(u,v)) add(u,v),add(v,u);
}
K=sqrt(n);
if(K*K!=n) K++;
dep[1]=1;dfs(1);
while(!Q.empty())
{
node tmp=Q.top();Q.pop();
int u=tmp.u;
if(vis[u]) continue;
dfs_vis(fa[u]);
res[++ans]=fa[u];
}
printf("%d\n",ans);
for(int i=1;i<=ans;i++) printf("%d ",res[i]);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9736kb
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 1 1 1
result:
ok correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 7720kb
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 3)