QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#122545#6634. Central Subsetinstallb#WA 14ms10340kbC++141.2kb2023-07-10 18:42:412023-07-10 18:42:44

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-10 18:42:44]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:10340kb
  • [2023-07-10 18:42:41]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int N=2e5+10;
int T,n,m,o,f[N],cnt,dp[N][2];
vector<int> G[N];bool b[N];
int gfa(int x){
    return f[x]^x?f[x]=gfa(f[x]):x;
}
void dfs(int u,int p){
    dp[u][0]=n+1;dp[u][1]=0;
    for(int &v:G[u]) if(v^p){
        dfs(v,u);
        dp[u][0]=min(dp[u][0],dp[v][0]+1);
        dp[u][1]=max(dp[u][1],dp[v][1]+1);
    }
    if(dp[u][0]+dp[u][1]<=o){
        dp[u][1]=dp[u][0]-o;
    }
    else if(dp[u][1]==o){
        dp[u][0]=0;
        dp[u][1]=-o;
        ++cnt;b[u]=1;
    }
}
int main(){
    scanf("%d",&T);
    while(T--){
        cnt=0;
        scanf("%d%d",&n,&m);
        o=(int)sqrt(n+0.5);
        if(o*o<n) ++o;
        rep(i,1,n) f[i]=i;
        rep(i,1,m){
            int u,v;scanf("%d%d",&u,&v);
            if(gfa(u)!=gfa(v)){
                f[gfa(u)]=gfa(v);
                G[u].push_back(v);
                G[v].push_back(u);
            }
        }
        dfs(1,0);
        printf("%d\n",cnt);
        rep(i,1,n) if(b[i]) printf("%d ",i);puts("");
        rep(i,1,n) b[i]=0,dp[i][0]=dp[i][1]=0,G[i].clear();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 14ms
memory: 10340kb

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:

2
3 11 
1
1 
1
2 
0

0

1
6 
0

1
4 
1
10 
0

2
5 15 
1
3 
1
2 
1
5 
0

2
3 11 
1
1 
0

1
2 
0

1
2 
1
3 
1
4 
1
5 
0

2
3 11 
1
1 
1
5 
1
1 
0

2
6 16 
1
2 
1
4 
1
7 
0

1
3 
1
2 
1
3 
2
6 7 
0

1
8 
1
1 
1
3 
1
2 
0

1
6 
1
3 
1
3 
1
5 
0

2
3 13 
1
1 
1
3 
1
4 
0

2
4 12 
1
2 
1
2 
1
1 
0

1
2 
1...

result:

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