Submission #838991

# Submission time Handle Problem Language Result Execution time Memory
838991 2023-08-28T13:03:57 Z VMaksimoski008 Traffic (IOI10_traffic) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

vector<vector<int> > graph;
vector<int> pop;
vector<ll> sub;
int ans = -1;
ll currBest = 1e9;

void getSub(int u, int p) {
    sub[u] += pop[u];

    for(int &v : graph[u]) {
        if(v == p) continue;
        getSub(v, u);
        sub[u] += sub[v];
    }
}

void dfs(int u, int p) {
    ll here = sub[0] - sub[u];

    for(int &v : graph[u]) {
        if(v == p) continue;
        here = max(here, sub[v]);
    }

    if(here < currBest) {
        currBest = here;
        ans = u;
    }

    //cout << u << " " << here << '\n';

    for(int &v : graph[u]) {
        if(v == p) continue;
        dfs(v, u);
    }
}

int LocalCentre(int n, int p[], int s[], int d[]) {
    pop = p;
    graph.resize(n);
    sub.resize(n, 0);

    for(int i=0; i<n-1; i++) {
        graph[s[i]].push_back(d[i]);
        graph[d[i]].push_back(s[i]);
    }

    getSub(0, 0);
    dfs(0, 0);
    //cout << currBest << '\n';
    return ans;
}

// int32_t main() {
//     setIO();

//     int n;
//     cin >> n;
//     vector<int> p(n);
//     vector<int> s(n);
//     vector<int> d(n);

//     for(int &x : p) cin >> x;

//     for(int i=0; i<n-1; i++) {
//         cin >> s[i] >> d[i];
//     }

//     cout << LocalCentre(n, p, s, d) << '\n';
//     return 0;
// }

Compilation message

traffic.cpp: In function 'int LocalCentre(int, int*, int*, int*)':
traffic.cpp:68:11: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'int*')
   68 |     pop = p;
      |           ^
In file included from /usr/include/c++/10/vector:72,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from traffic.cpp:1:
/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/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from traffic.cpp:1:
/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)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~