Submission #1073386

# Submission time Handle Problem Language Result Execution time Memory
1073386 2024-08-24T13:53:47 Z blushingecchigirl Connecting Supertrees (IOI20_supertrees) C++17
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <vector>
#define pb push_back

struct dsu {
    vector<int> parent, rank;
    int size;

    dsu(int sz) {
        size = sz;
        rank.assign(size, 1);
        parent.resize(size);
        for(int i = 0; i<size; i++) parent[i] = i;
    }
    int search(int v) {
        if(v == parent[v]) return v;
        return parent[v] = search(parent[v]);
    }
    void connect(int v, int u) {
        v = search(v);
        u = search(u);
        if(v == u) return;
        if(rank[v]>=rank[u]) parent[u] = v;
        else parent[v] = u;
        if(rank[v] == rank[u]) rank[v]++;
        return;
    }
};

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool ctr = 1, b[n][n]{};
    
    vector<int> a[n];
    dsu d = dsu(n);
    for(int i = 0; i<n; i++) {
        for(int j = 0; j<n; j++) {
            if(p[i][j]) d.connect(i, j);
        }
    }
    for(int i = 0; i<n; i++) {
        a[d.search(i)].pb(i);
    }
    for(int i = 0; i<n; i++) {
        if(a[i].size()<=1) continue;
        int pth = p[a[i][0]][a[i][1]];
        for(int ii:a[i]) {
            for(int j:a[i]) {
                if(ii == j) continue;
                if(p[ii][j] != pth) ctr = false;
            }
        }
        for(size_t ii = 1; ii<a[i].size(); ii++) {
            b[ii][ii-1] = b[ii-1][ii] = 1;
        }
        if(pth == 2) b[a[i][0]][a[i].back()] = b[a[i].back()][a[i][0]] = 1;
    }
	if(ctr) build(b);
	return 1;
}

Compilation message

supertrees.cpp:6:5: error: 'vector' does not name a type
    6 |     vector<int> parent, rank;
      |     ^~~~~~
supertrees.cpp: In constructor 'dsu::dsu(int)':
supertrees.cpp:11:9: error: 'rank' was not declared in this scope; did you mean 'std::rank'?
   11 |         rank.assign(size, 1);
      |         ^~~~
      |         std::rank
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: 'std::rank' declared here
 1359 |     struct rank
      |            ^~~~
supertrees.cpp:12:9: error: 'parent' was not declared in this scope
   12 |         parent.resize(size);
      |         ^~~~~~
supertrees.cpp: In member function 'int dsu::search(int)':
supertrees.cpp:16:17: error: 'parent' was not declared in this scope
   16 |         if(v == parent[v]) return v;
      |                 ^~~~~~
supertrees.cpp:17:16: error: 'parent' was not declared in this scope
   17 |         return parent[v] = search(parent[v]);
      |                ^~~~~~
supertrees.cpp: In member function 'void dsu::connect(int, int)':
supertrees.cpp:23:12: error: 'rank' was not declared in this scope; did you mean 'std::rank'?
   23 |         if(rank[v]>=rank[u]) parent[u] = v;
      |            ^~~~
      |            std::rank
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: 'std::rank' declared here
 1359 |     struct rank
      |            ^~~~
supertrees.cpp:23:30: error: 'parent' was not declared in this scope
   23 |         if(rank[v]>=rank[u]) parent[u] = v;
      |                              ^~~~~~
supertrees.cpp:24:14: error: 'parent' was not declared in this scope
   24 |         else parent[v] = u;
      |              ^~~~~~
supertrees.cpp:25:12: error: 'rank' was not declared in this scope; did you mean 'std::rank'?
   25 |         if(rank[v] == rank[u]) rank[v]++;
      |            ^~~~
      |            std::rank
In file included from /usr/include/c++/10/bits/move.h:57,
                 from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/10/type_traits:1359:12: note: 'std::rank' declared here
 1359 |     struct rank
      |            ^~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:34:5: error: 'vector' was not declared in this scope
   34 |     vector<int> a[n];
      |     ^~~~~~
supertrees.cpp:34:5: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
supertrees.cpp:34:12: error: expected primary-expression before 'int'
   34 |     vector<int> a[n];
      |            ^~~
supertrees.cpp:42:9: error: 'a' was not declared in this scope
   42 |         a[d.search(i)].pb(i);
      |         ^
supertrees.cpp:45:12: error: 'a' was not declared in this scope
   45 |         if(a[i].size()<=1) continue;
      |            ^
supertrees.cpp:46:21: error: 'a' was not declared in this scope
   46 |         int pth = p[a[i][0]][a[i][1]];
      |                     ^
supertrees.cpp:58:16: error: could not convert '(bool (*)[n])(& b)' from 'bool (*)[n]' to 'std::vector<std::vector<int> >'
   58 |  if(ctr) build(b);
      |                ^
      |                |
      |                bool (*)[n]