QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204989#6634. Central SubsetGeospiza#WA 16ms25548kbC++201.3kb2023-10-07 14:33:462023-10-07 14:33:46

Judging History

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

  • [2023-10-07 14:33:46]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:25548kb
  • [2023-10-07 14:33:46]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;++i)
typedef pair<ll,ll> pll;
const ll N=4e5+5;
vector<ll>vec[N],vcc[N];
ll t,n,m,k,tt,tp;
ll vis[N];
void dfs(ll u,ll pre)
{
    if(vis[u])return ;
    vis[u]=1;
    if(pre!=0){
    vcc[u].pb(pre);
    vcc[pre].pb(u);}
    for(auto v:vec[u])if(v!=pre)dfs(v,u);
}
ll dep[N],vc[N];
void dfss(ll u,ll pre)
{
    dep[u]=dep[pre]+1;
    vc[dep[u]]=u;
    for(auto v:vcc[u])if(v!=pre)dfss(v,u);
}
int	 main(){
	//dabiao();
    ios::sync_with_stdio(0); cin.tie(0);
	int T=1;
	cin>>T;
	while(T--)
    {
        cin>>n>>m;
        rep(i,1,n)
        {
            vis[i]=vc[i]=0;
            vec[i].clear(),vcc[i].clear();
        }
        rep(i,1,m)
        {
            ll u,v;
            cin>>u>>v;
            vec[u].pb(v);
            vec[v].pb(u);
        }
        dfs(1,0);
        dfss(1,0);
        ll B=(ll)sqrt(n-1.0)+1,bs=B;
        vector<ll>v;
        while(B<=n)
        {
            if(vc[B])v.pb(vc[B]);
            B+=bs;
        }
        cout<<v.size()<<"\n";
        for(auto x:v)cout<<x<<" ";
        cout<<"\n";
    }
}
/*
4
1 1 1 1
*/

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 24296kb

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

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 16ms
memory: 25548kb

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
4 8 12 
1
3 
1
4 
1
2 
1
2 
3
3 6 9 
1
2 
2
4 14 
2
4 14 
0

4
5 10 15 20 
2
3 8 
1
8 
1
6 
1
3 
3
4 8 12 
1
3 
1
2 
1
4 
0

2
2 4 
2
5 8 
2
10 8 
1
8 
1
4 
3
4 8 12 
1
5 
2
4 8 
1
2 
1
4 
4
5 10 15 20 
1
5 
2
4 8 
2
5 15 
1
6 
2
3 6 
1
3 
1
9 
2
5 16 
1
3 
3
4 8 12 
1
3 
1
9 
2
2 4 
1
5 
2
4 8 
1...

result:

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