QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127084#6634. Central SubsetEthan_xu#WA 18ms11344kbC++201.1kb2023-07-19 12:52:532023-07-19 12:54:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-19 12:54:02]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:11344kb
  • [2023-07-19 12:52:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,T,f[N],dep[N],w[N],mx[N],k,s[N];
int fi(int x){return x==f[x]? x:f[x]=fi(f[x]);}
vector<int>E[N],ans;
void dfs(int x,int f){
    // printf("___%d %d\n",x,f);
    dep[x]=dep[f]+1;
    mx[x]=dep[x];
    for(auto to:E[x]){
        if(to==f)continue;
        dfs(to,x);
        mx[x]=max(mx[x],mx[to]);
    }
    if(mx[x]-dep[x]==k){
        ans.push_back(x);
        mx[x]=dep[x]-1;
    }
}
void slv(){
    scanf("%d %d",&n,&m);
    k=ceil(sqrt(n));
    ans.clear();
    for(int i=1;i<=n;++i)E[i].clear();
    for(int i=1;i<=n;++i)f[i]=i,s[i]=0;
    for(int i=1;i<=m;++i){
        int x,y;
        scanf("%d %d",&x,&y);
        if(fi(x)==fi(y))continue;
        f[fi(x)]=fi(y);
        s[x]++,s[y]++;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    int rt=1;
    for(int i=1;i<=n;++i)if(s[i]==1)rt=i;
    dfs(rt,0);
    if(ans.empty())ans.push_back(rt);
    printf("%d\n",(int)ans.size());
    for(auto x:ans)printf("%d ",x);
    puts("");
}
int main(){
    scanf("%d",&T);
    while(T--)slv();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
3 
1
4 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 18ms
memory: 11344kb

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
5 10 15 
1
4 
1
5 
1
2 
1
2 
2
4 8 
1
2 
1
5 
2
6 16 
1
16 
3
6 12 18 
1
4 
1
5 
1
10 
1
5 
3
5 10 15 
1
4 
1
2 
1
4 
1
19 
1
3 
1
4 
1
5 
1
8 
1
6 
3
5 10 15 
1
5 
2
5 16 
1
3 
1
8 
3
6 12 18 
1
5 
1
5 
2
6 16 
1
6 
1
4 
1
5 
1
5 
2
6 7 
1
8 
2
5 10 
1
4 
1
5 
1
3 
1
9 
2
5 10 
1
6 
1
5 
1
7 
1
8...

result:

wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1972)