Submission #704458

# Submission time Handle Problem Language Result Execution time Memory
704458 2023-03-02T06:59:24 Z bin9638 ICC (CEOI16_icc) C++17
100 / 100
140 ms 748 KB
#ifndef SKY
#include<icc.h>
#endif // SKY

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fs first
#define sc second
#define N 110
#define pb push_back

struct DSU
{
    int lab[N];

    void init(int n)
    {
        memset(lab,-1,sizeof(lab));
    }

    int root(int u)
    {
        if(lab[u]<0)
            return u;
        return(lab[u]=root(lab[u]));
    }

    void update(int u,int v)
    {
        if((u=root(u))==(v=root(v)))
            return;
        if(lab[u]>lab[v])
            swap(u,v);
        lab[u]+=lab[v];
        lab[v]=u;
    }
}T;

int edge[N][N];

#ifdef SKY
void setRoad(int u, int v)
{
    cout<<u<<" "<<v<<endl;
}

int query(int size_a,int size_b,int a[],int b[])
{
    for(int i=0;i<size_a;i++)
        for(int j=0;j<size_b;j++)
            if(edge[a[i]][b[j]]==1)
                return 1;
    return 0;
}
#endif // SKY

int make_query(vector<int>L,vector<int>R)
{
    int a[N]={},b[N]={};
    for(int i=0;i<L.size();i++)
        a[i]=L[i];
    for(int i=0;i<R.size();i++)
        b[i]=R[i];
    return query(L.size(),R.size(),a,b);
}

void chia_tap(vector<int>&L,vector<int>R)
{
    vector<int>luu;
    int sz=L.size();
    for(int i=1;i*2<=sz;i++)
    {
        luu.pb(L.back());
        L.pop_back();
    }
    if(make_query(L,R)==0)
        L=luu;
}

void solve(int n)
{
    #ifdef SKY
    int u,v;
    cin>>u>>v;
   // cout<<u<<" "<<v<<endl;
    edge[u][v]=edge[v][u]=1;
    #endif // SKY
    int dem=0;
    vector<int>lis[N],L,R;
    for(int i=1;i<=n;i++)
        if(T.root(i)==i)
        {
            dem++;
            for(int j=1;j<=n;j++)
                if(T.root(j)==i)
                    lis[dem].pb(j);
        }
    //cout<<dem<<endl;
    for(int i=0;(1<<i)<=dem;i++)
    {
        L.clear();
        R.clear();
        for(int j=1;j<=dem;j++)
            if((j>>i)&1)
            {
                for(auto u:lis[j])
                    L.pb(u);
            }else
            {
                for(auto u:lis[j])
                    R.pb(u);
            }
       // cout<<i<<" "<<L.size()<<" "<<R.size()<<" "<<make_query(L,R)<<endl;
        if(make_query(L,R))
            break;
    }
    while(L.size()>1)
        chia_tap(L,R);
    swap(L,R);
    while(L.size()>1)
        chia_tap(L,R);
    setRoad(L[0],R[0]);
    T.update(L[0],R[0]);
}

void run(int n)
{
    T.init(n);
    for(int i=1;i<n;i++)
        solve(n);
}

#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    int n;
    cin>>n;
    run(n);
    return 0;
}
#endif // SKY

Compilation message

icc.cpp: In function 'int make_query(std::vector<int>, std::vector<int>)':
icc.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0;i<L.size();i++)
      |                 ~^~~~~~~~~
icc.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i=0;i<R.size();i++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 95 queries used.
2 Correct 5 ms 468 KB Ok! 95 queries used.
# Verdict Execution time Memory Grader output
1 Correct 31 ms 500 KB Ok! 519 queries used.
2 Correct 35 ms 432 KB Ok! 644 queries used.
3 Correct 35 ms 496 KB Ok! 633 queries used.
# Verdict Execution time Memory Grader output
1 Correct 113 ms 504 KB Ok! 1419 queries used.
2 Correct 140 ms 500 KB Ok! 1592 queries used.
3 Correct 118 ms 496 KB Ok! 1599 queries used.
4 Correct 110 ms 428 KB Ok! 1505 queries used.
# Verdict Execution time Memory Grader output
1 Correct 111 ms 492 KB Ok! 1496 queries used.
2 Correct 126 ms 492 KB Ok! 1504 queries used.
3 Correct 117 ms 504 KB Ok! 1551 queries used.
4 Correct 108 ms 504 KB Ok! 1492 queries used.
# Verdict Execution time Memory Grader output
1 Correct 112 ms 512 KB Ok! 1524 queries used.
2 Correct 111 ms 492 KB Ok! 1521 queries used.
3 Correct 113 ms 512 KB Ok! 1564 queries used.
4 Correct 115 ms 512 KB Ok! 1552 queries used.
5 Correct 111 ms 468 KB Ok! 1487 queries used.
6 Correct 126 ms 748 KB Ok! 1548 queries used.
# Verdict Execution time Memory Grader output
1 Correct 117 ms 488 KB Ok! 1552 queries used.
2 Correct 113 ms 496 KB Ok! 1563 queries used.