QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134889#6634. Central SubsetS_Explosion#WA 32ms7636kbC++201.3kb2023-08-05 09:45:252023-08-05 09:45:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 09:45:30]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:7636kb
  • [2023-08-05 09:45:25]
  • 提交

answer

#include<iostream>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;
struct Edge{
    int to,nxt;
}e[400005];
vector<int> ans;
int T,n,m,num,h[200005],fa[200005],f[200005],lim;
int fnd(int x){
    if(x==fa[x])
        return x;
    return fa[x]=fnd(fa[x]);
}
void add(int u,int v){
    e[++num].to=v;
    e[num].nxt=h[u];
    h[u]=num;
}
void merge(int u,int v){
    int nu=fnd(u),nv=fnd(v);
    if(nu==nv)
        return;
    fa[nu]=nv;
    add(u,v);add(v,u);
}
void dfs(int u,int fa){
    int i,v;
    for(i=h[u];i;i=e[i].nxt){
        v=e[i].to;
        if(v!=fa){
            dfs(v,u);
            f[u]=max(f[u],f[v]+1);
        }
    }
    if(f[u]==lim){
        f[u]=0;
        ans.push_back(u);
    }
}
int main(){
    ios::sync_with_stdio(false);
    int i,u,v;
    cin>>T;
    while(T--){
        ans.clear();
        cin>>n>>m;
        for(i=1;i<=n;i++)
            h[i]=f[i]=0;
        num=0;
        for(lim=1;lim*lim<n;lim++);
        for(i=1;i<=n;i++)
            fa[i]=i;
        for(i=1;i<=m;i++){
            cin>>u>>v;
            merge(u,v);
        }
        dfs(1,0);
        cout<<int(ans.size())<<"\n";
        for(auto i:ans)
            cout<<i<<" ";
        cout<<"\n";
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5468kb

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: 32ms
memory: 7636kb

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 7 3 
1
1 
1
2 
0

0

2
6 3 
0

1
4 
2
10 3 
0

3
15 10 5 
1
3 
1
2 
1
5 
0

3
11 7 3 
1
1 
0

1
2 
0

1
2 
1
3 
1
4 
2
5 1 
0

3
11 7 3 
1
1 
2
5 1 
1
1 
0

4
16 11 6 1 
1
2 
1
4 
2
7 4 
0

1
3 
1
2 
1
3 
3
6 7 1 
0

2
8 4 
1
1 
1
3 
1
2 
0

2
6 2 
1
3 
1
3 
2
5 1 
0

3
13 8 3 
1
1 
1
3 
1
4 
0...

result:

wrong answer Integer 0 violates the range [1, 2] (test case 4)