QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733835#6634. Central SubsetVedant18#WA 11ms3704kbC++233.8kb2024-11-10 21:28:272024-11-10 21:28:27

Judging History

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

  • [2024-11-10 21:28:27]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3704kb
  • [2024-11-10 21:28:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define in(a, b) for (ll i = (a); i <= (b); i++)                // in using i
#define inj(a, b) for (ll j = (a); j <= (b); j++)               // in using j
#define ink(a, b) for (ll k = (a); k <= (b); k++)               // in using k
#define inl(a, b) for (ll l = (a); l <= (b); l++)               // in using l
#define inr(a, b) for(ll i = (a); i >= (b); i--)                // in reverse
#define inrj(a, b) for(ll j = (a); j >= (b); j--)                // in reverse
#define inrk(a, b) for(ll k = (a); k >= (b); k--)                // in reverse
#define inrl(a, b) for(ll l = (a); l >= (b); l--)                // in reverse
#define tt ll tcs; cin>>tcs; while(tcs--)                       // include test cases
#define ina(arr,n) ll arr[(n+1)]={0}; in(1,n) cin>>arr[i]       // input arr of n elements
#define inv(vec,n) vector<ll> vec(n+1); vec[0]=0; in(1,n) cin>>vec[i]; // input vector of n elements
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pll pair <ll,ll>
#define vpll vector <pll>
#define sll set <ll>
#define vll vector<ll>
#define mll map <ll,ll>
#define all(x) x.begin(), x.end()
const ll mod=1e9+7;
#define vvll vector<vll>
#define pref(p,a,n) vll p(n+1); in(1,n) p[i]=p[i-1]+a[i];
#define vec2(a,n,m) vvll a(n+1,vll(m+1))
// #define vec2(a,n,m,val) vvll a(n+1,vll(m+1,val))

#define vec3(a,l,m,n) vector<vvll>a(l+1,vvll(m+1,vll(n+1)));
// #define vec3(a,l,m,n,val) vector<vvll>a(l+1,vvll(m+1,vll(n+1,val)));
# define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// DSU;
vll dsu_parent;
vll dsu_size;
void initiate_dsu(ll n){
    dsu_parent.clear();
    dsu_size.clear();
    dsu_parent.resize(n+1);
    in(1,n) dsu_parent[i]=i;
    dsu_size.assign(n+1,1);
}
ll find_set(ll v) {
    if (v == dsu_parent[v])
        return v;
    return dsu_parent[v] = find_set(dsu_parent[v]);
}
void make_set(ll v) {
    dsu_parent[v] = v;
    dsu_size[v] = 1;
}
 
void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (dsu_size[a] < dsu_size[b])
            swap(a, b);
        dsu_parent[b] = a;
        dsu_size[a] += dsu_size[b];
    }
}
int main(){
    FAST
    tt{
        ll n,m;
        cin>>n>>m;
        initiate_dsu(n);

        vvll adj(n+1);
        in(1,m){
            ll a,b;
            cin>>a>>b;
            if(find_set(a)!=find_set(b)){
                union_sets(a,b);
                adj[a].push_back(b);
                adj[b].push_back(a);
            }
        }
        //tree
        vll dis(n+1);
        vll sett;
        ll mxdis=sqrt(n);
        if((mxdis*mxdis)>=n){

        }
        else{
            mxdis++;
        }

        function<void(int,int)>dfs=[&](int v, int p){
            for(auto x:adj[v]){
                if(x!=p){
                    dfs(x,v);
                    dis[v]=max(dis[v],1+dis[x]);
                }
            }
            if(dis[v]==mxdis){
                dis[v]=0;
                sett.push_back(v);
            }
        };
        dfs(1,0);
        if(sett.size()==0){
            sett.push_back(1);
        }
        if((sett.back()!=1)&&(adj[1].size()!=1)){
            ll mx=0;
            ll mn=n+1;
            for(auto x:adj[1]){
                mx=max(mx,1+dis[x]);
                mn=min(mn,1+dis[x]);

            }

                if((mx+mn)<=mxdis){

                }
                else{
                    sett.push_back(1);
                }
            

        }
        if(sett.size()<=mxdis){
            cout<<sett.size()<<endl;
            for(auto x:sett){
                cout<<x<<' ';
            }
            cout<<endl;
        }
        else{
        cout<<-1<<endl;;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

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: 11ms
memory: 3704kb

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 
1
1 
1
1 
2
6 3 
1
1 
1
4 
2
10 3 
1
1 
3
15 10 5 
1
3 
1
2 
1
5 
1
1 
3
11 7 3 
1
1 
1
1 
1
2 
1
1 
1
2 
1
3 
1
4 
2
5 1 
1
1 
3
11 7 3 
1
1 
2
5 1 
1
1 
1
1 
4
16 11 6 1 
1
2 
1
4 
2
7 4 
1
1 
1
3 
1
2 
1
3 
3
7 6 1 
1
1 
2
8 4 
1
1 
1
3 
1
2 
1
1 
2
6 2 
1
3 
1
3 
2
5 1 
1
1 
...

result:

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