Submission #843852

# Submission time Handle Problem Language Result Execution time Memory
843852 2023-09-04T16:02:18 Z nonono Closing Time (IOI23_closing) C++17
Compilation error
0 ms 0 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 200000;

vector<vector<int>> adj(mxN);
long long d[2][mxN];

void dfs(int u, int par, int type) {
    for(auto [v, w] : adj[u]) {
        if(v == par) continue ;
        
        d[type][v] = d[type][u] + w;
        dfs(v, u);
    }
}

int sub1(int N, long long K) {
    vector<long long> a;
    
    for(int i = 0; i < N; i ++) {
        a.push_back(d[0][i]);
        a.push_back(d[1][i]);
    }
    
    sort(a.begin(), a.end());
    
    long long sum = 0;
    int ans = 0;
    
    for(long long x : a) {
        if(sum + x > K) break ;
        sum += x;
        ans += 1;
    }
    
    return ans;
}

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
    
    for(int i = 0; i < N - 1; i ++) {
        adj[U[i]].push_back({V[i], W[i]});
        adj[V[i]].push_back({U[i], W[i]});
    }
    
    dfs(X, X, 0);
    dfs(Y, Y, 1);
    
    if(d[0][Y] > 2 * K) return sub1(N, K); 
}

// int main() {
//     int N, X, Y;
//     long long K;
//     cin >> N >> X >> Y >> K;
    
//     vector<int> U(N), V(N), W(N);
    
//     for(int i = 0; i < N - 1; i ++) {
//         cin >> U[i] >> V[i] >> W[i];
//     }
    
//     cout << max_score(N, X, Y, K, U, V, W) << "\n";
//     return 0;
// }

Compilation message

closing.cpp: In function 'void dfs(int, int, int)':
closing.cpp:11:14: error: cannot decompose non-array non-class type 'int'
   11 |     for(auto [v, w] : adj[u]) {
      |              ^~~~~~
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:44:41: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   44 |         adj[U[i]].push_back({V[i], W[i]});
      |                                         ^
In file included from /usr/include/c++/10/vector:67,
                 from closing.h:1,
                 from closing.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
closing.cpp:45:41: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   45 |         adj[V[i]].push_back({U[i], W[i]});
      |                                         ^
In file included from /usr/include/c++/10/vector:67,
                 from closing.h:1,
                 from closing.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
closing.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
   52 | }
      | ^