답안 #1073588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073588 2024-08-24T16:21:50 Z blushingecchigirl 슈퍼트리 잇기 (IOI20_supertrees) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#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;
    }
};

void build(std::vector<std::vector<int>> b);
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	bool ctr = 1;
    vector<vector<int>> b(n);
    for(int i = 0; i<n; i++) b[i].resize(n, 0);
    
    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++) {
        int sz = a[i].size();
        for(int ii = 0; ii<sz; ii++) {
            for(int j = 0; j<sz; j++) {
                if(p[a[ii]][a[j]] == 0 || p[a[ii]][a[j]] == 3) ctr = 0;
            }
        }
        if(sz<=1) continue;
        vector<int> tree[sz], circle;
        dsu dd = dsu(sz);
        for(int ii = 0; ii<sz; ii++) {
            for(int j = 0; j<sz; j++) {
                if(p[a[i][ii]][a[i][j]] == 1) dd.connect(ii, j);
            }
        }
        for(int ii = 0; ii<sz; ii++) {
            tree[dd.search(ii)].pb(a[i][ii]);
        }
        for(int ii = 0; ii<sz; ii++) {
            if(tree[ii].size() == 0) continue;
            if(tree[ii].size()>1) {
                for(size_t j = 1; j<tree[ii].size(); j++) b[tree[ii][j]][tree[ii][j-1]] = b[tree[ii][j-1]][tree[ii][j]] = 1;
            }
            for(size_t iii = 0; iii < tree[ii].size(); iii++) {
                for(size_t j = 0; j < tree[ii].size(); j++) {
                    if(p[tree[ii][iii]][tree[ii][j]] != 1) ctr = 0;
                }
            }
            circle.pb(tree[ii][0]);
        }
        for(size_t ii = 1; ii<circle.size(); ii++) {
            b[circle[ii]][circle[ii-1]] = b[circle[ii-1]][circle[ii]] = 1;
        }
        if(circle.size()>1) b[circle[0]][circle.back()] = b[circle.back()][circle[0]] = 1;
        if(circle.size() == 2) ctr = 0;
    }
	if(ctr) build(b);
	return ctr;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:51:21: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   51 |                 if(p[a[ii]][a[j]] == 0 || p[a[ii]][a[j]] == 3) ctr = 0;
      |                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from supertrees.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
supertrees.cpp:51:44: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   51 |                 if(p[a[ii]][a[j]] == 0 || p[a[ii]][a[j]] == 3) ctr = 0;
      |                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from supertrees.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~