답안 #433586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433586 2021-06-20T07:56:15 Z SAAD 슈퍼트리 잇기 (IOI20_supertrees) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include "supertrees.h"
using namespace std;
bool ok;
int tree[10002] , n;
vector<vector<int>> a;
vector <int> x[1002];
int dfs( int idx , int lab ) {
    tree[idx] = lab;
    for (auto i : x[idx]) {
        if (tree[i] == lab) continue;
        if (tree[i] == -1) {
            dfs(i,lab);
        }
        else {
            ok = false;
        }
    }
    return 0;
}
int construct(vector<vector<int>> p) {
    n = (int)p.size();
    ok = true;
    memset(tree,-1,sizeof(tree));
    a = p;
    for (int i = 0; i < (int)a.size(); i++) {
        for (int j = 0; j < (int)a.size(); j++) {
            a[i][j] = 0;
            if (i == j) continue;
            if (p[i][j] != p[j][i] || p[i][i] != 1 ) return 0;
            if (p[i][j] == 1) {
                x[i].push_back(j);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (tree[i] == -1) {
            dfs(i,i);
            if (!ok) return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (tree[i] == i) {
            a[i] = p[i];
            a[i][i] = 0;
        }
        else {
            a[tree[i]] = 1;
        }
    }
    build(a);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:52:26: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and 'int')
   52 |             a[tree[i]] = 1;
      |                          ^
In file included from /usr/include/c++/10/vector:72,
                 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 supertrees.cpp:3:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
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 supertrees.cpp:3:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~