Submission #864758

# Submission time Handle Problem Language Result Execution time Memory
864758 2023-10-23T14:32:10 Z andrei_boaca Connecting Supertrees (IOI20_supertrees) C++17
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;

int n;
vector<vector<int>> adj;
vector<int> muchii[1005],edges[1005];
int comp[1005],nrcomp;
bool use[1005];
vector<int> v,nodes;
bool good=1;
void calc(int nod)
{
    use[nod]=1;
    v.push_back(nod);
    for(int i:edges[nod])
        if(!use[i])
            calc(i);
}
void dfs(int nod)
{
    nodes.push_back(nod);
    comp[nod]=nrcomp;
    for(int i:muchii[nod])
        if(!comp[i])
            dfs(i);
}
void solve()
{
    for(int i:v)
        for(int j:v)
            if(p[i][j]==0)
            {
                good=0;
                return;
            }
    vector<int> reprez;
    for(int i:v)
        for(int j:v)
            if(i!=j&&p[i][j]==1)
                muchii[i].push_back(j);
    for(int i:v)
        if(comp[i]==0)
        {
            nrcomp++;
            nodes.clear();
            dfs(i);
            reprez.push_back(nodes[0]);
            for(int j=1;j<nodes.size();j++)
            {
                int a=nodes[j-1];
                int b=nodes[j];
                adj[a][b]=1;
                adj[b][a]=1;
            }
        }
    if(reprez.size()==2)
    {
        good=0;
        return;
    }
    int lg=reprez.size();
    for(int i=0;i<reprez.size();i++)
    {
        int a=reprez[i];
        int b=reprez[(i+1)%lg];
        if(a!=b)
            adj[a][b]=adj[b][a]=1;
    }
    for(int i:v)
        for(int j:v)
            if(i!=j)
            {
                if(p[i][j]==1&&comp[i]!=comp[j])
                {
                    good=0;
                    return;
                }
                if(p[i][j]==2&&comp[i]==comp[j])
                {
                    good=0;
                    return;
                }
            }
}
int construct(std::vector<std::vector<int>> p)
{
    good=1;
    n=p.size();
    adj.resize(n);
    for(int i=0;i<n;i++)
        adj[i].resize(n);
    bool sub1=1;
    bool sub2=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            sub1&=(p[i][j]<=2);
            if(p[i][j]>0&&i!=j)
                edges[i].push_back(j);
        }
    if(sub1)
    {
        for(int i=0;i<n;i++)
            if(!use[i])
            {
                v.clear();
                calc(i);
                solve();
                if(good==0)
                    return 0;
            }
        build(adj);
        return 1;
    }
	return 0;
}

Compilation message

supertrees.cpp: In function 'void solve()':
supertrees.cpp:34:16: error: 'p' was not declared in this scope
   34 |             if(p[i][j]==0)
      |                ^
supertrees.cpp:42:22: error: 'p' was not declared in this scope
   42 |             if(i!=j&&p[i][j]==1)
      |                      ^
supertrees.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int j=1;j<nodes.size();j++)
      |                         ~^~~~~~~~~~~~~
supertrees.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=0;i<reprez.size();i++)
      |                 ~^~~~~~~~~~~~~~
supertrees.cpp:76:20: error: 'p' was not declared in this scope
   76 |                 if(p[i][j]==1&&comp[i]!=comp[j])
      |                    ^
supertrees.cpp:81:20: error: 'p' was not declared in this scope
   81 |                 if(p[i][j]==2&&comp[i]==comp[j])
      |                    ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:96:10: warning: unused variable 'sub2' [-Wunused-variable]
   96 |     bool sub2=1;
      |          ^~~~