Submission #764596

# Submission time Handle Problem Language Result Execution time Memory
764596 2023-06-23T16:16:28 Z alexander707070 Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "supertrees.h"
#define MAXN 1007
using namespace std;

int n,k;
vector<int> cycle[MAXN];
vector<int> v[MAXN];
vector< vector<int> > ans;
bool li[MAXN];

int dsu[MAXN],sz[MAXN];

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

void connect(int x,int y){
    if(sz[root(x)]<sz[root(y)])swap(x,y);
    sz[root(x)]+=sz[root(y)];
    dsu[root(y)]=root(x);
    add_edge(x,y);
}

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

void dfs(int x){
    li[x]=true;
    cycle[k].push_back(x);
    for(int i=0;i<v[x].size();i++){
        if(!li[v[x][i]])dfs(v[x][i]);
    }
}

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

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

    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==2){
                v[i].push_back(f);
                v[f].push_back(i);
            }
        }
    }

    for(int i=0;i<n;i++){
        dsu[i]=i; sz[i]=1;
    }
    
    for(int i=0;i<n;i++){
        if(!li[i]){
            k++; dfs(i);
            for(int f=0;f<cycle[k].size();f++){
                for(int d=f+1;d<cycle[k].size();d++){
                    if(p[cycle[k][f]][cycle[k][d]]!=2)return 0;
                }
            }

            sz[k]=int(cycle[k].size());
            for(int f=0;f<cycle[k].size()-1;f++){
                connect(cycle[k][f],cycle[k][(f+1)%int(cycle[k].size())]);
            }
            add_edge(cycle[k].back(),cycle[k][0]);
        }
    }

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

    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            if(p[i][f]==0 and root(i)==root(f))return 0;
        }
    }

    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'void connect(int, int)':
supertrees.cpp:24:5: error: 'add_edge' was not declared in this scope
   24 |     add_edge(x,y);
      |     ^~~~~~~~
supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for(int f=0;f<cycle[k].size();f++){
      |                         ~^~~~~~~~~~~~~~~~
supertrees.cpp:63:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |                 for(int d=f+1;d<cycle[k].size();d++){
      |                               ~^~~~~~~~~~~~~~~~
supertrees.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int f=0;f<cycle[k].size()-1;f++){
      |                         ~^~~~~~~~~~~~~~~~~~