Submission #790877

# Submission time Handle Problem Language Result Execution time Memory
790877 2023-07-23T09:10:43 Z alexander707070 Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
7 ms 14292 KB
#include<bits/stdc++.h>
#include "supertrees.h"
#define MAXN 300007
using namespace std;

int n;
int dsu[MAXN],dsu2[MAXN];
vector<int> comp[MAXN],comp2[MAXN];
vector< vector<int> > ans;

int root(int x){
    if(dsu[x]==x)return x;
    dsu[x]=root(dsu[x]);
    return dsu[x];
}

void mergev(int x,int y){
    dsu[root(x)]=root(y);
}

int root2(int x){
    if(dsu2[x]==x)return x;
    dsu2[x]=root(dsu2[x]);
    return dsu2[x];
}

void mergev2(int x,int y){
    dsu2[root2(x)]=root2(y);
}

void add_edge(int x,int y){
    ans[x][y]=ans[y][x]=1;
}

int construct(vector< vector<int> > p){
    n=int(p.size());

    ans.resize(n);
    for(int i=0;i<n;i++){
        ans[i].resize(n);
    }

    for(int i=0;i<n;i++){
        dsu[i]=dsu2[i]=i;
    }

    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==1)mergev(i,f);
        }
    }

    for(int i=0;i<n;i++){
        comp[root(i)].push_back(i);
    }

    for(int i=0;i<n;i++){
        if(comp[i].empty())continue;

        for(int f=0;f<comp[i].size();f++){
            for(int k=f+1;k<comp[i].size();k++){
                if(p[comp[i][f]][comp[i][k]]!=1)return 0;
            }
        }
        for(int f=0;f<comp[i].size()-1;f++){
            add_edge(comp[i][f],comp[i][f+1]);
        }
    }
    
    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==2)mergev2(root(i),root(f));
        }
    }

    for(int i=0;i<n;i++){
        if(comp[i].empty())continue;
        comp2[root2(i)].push_back(i);
    }

    for(int i=0;i<n;i++){
        if(comp2[i].empty())continue;

        for(int f=0;f<comp2[i].size();f++){
            for(int k=f+1;k<comp2[i].size();k++){
                for(int t:comp[comp2[i][f]]){
                    for(int s:comp[comp2[i][k]]){
                        if(p[t][s]!=2)return 0;
                    }
                }
            }
        }
        for(int f=0;f<comp2[i].size();f++){
            add_edge(comp2[i][f],comp2[i][(f+1)%int(comp2[i].size())]);
        }
    }

    build(ans);
    /*
    for(int i=0;i<ans.size();i++){
        for(int f=0;f<ans.size();f++){
            cout<<ans[i][f]<<" ";
        }
        cout<<"\n";
    }
    */
    return 1;
}

/*
int main(){
    construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
}
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int f=0;f<comp[i].size();f++){
      |                     ~^~~~~~~~~~~~~~~
supertrees.cpp:61:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for(int k=f+1;k<comp[i].size();k++){
      |                           ~^~~~~~~~~~~~~~~
supertrees.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int f=0;f<comp[i].size()-1;f++){
      |                     ~^~~~~~~~~~~~~~~~~
supertrees.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(int f=0;f<comp2[i].size();f++){
      |                     ~^~~~~~~~~~~~~~~~
supertrees.cpp:85:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             for(int k=f+1;k<comp2[i].size();k++){
      |                           ~^~~~~~~~~~~~~~~~
supertrees.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         for(int f=0;f<comp2[i].size();f++){
      |                     ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14292 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -