Submission #1086417

# Submission time Handle Problem Language Result Execution time Memory
1086417 2024-09-10T14:45:56 Z ehab_rafat Race (IOI11_race) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define LSB(i) ((i) & (-i))
#define ll long long
const int dx[]{-1,1,0,0,-1,-1,1,1};
const int dy[]{0,0,1,-1,-1,1,-1,1};
const int MOD = 1e9+7;
#define int ll


const int N = 2e5+5;
std::vector<array<int,2>> G[N];
map<int, int> vec[N];
int sum[N], dist[N], n, k, ans;

void dfs0(int u, int p, int s = 0, int d = 0){
    sum[u] = s;
    dist[u] = d;
    vec[u][s] = d;
    for(auto& nei : G[u]){
        int v = nei[0], w = nei[1];
        if(v==p) continue;
        dfs0(v, u, s+w, d+1);
    }
}

void dfs(int u, int p){
    int target = k + 2*sum[u];
    for(auto& nei : G[u]){
        int v = nei[0];
        if(v==p) continue;
        dfs(v, u);
        if(vec[v].size() > vec[u].size()) swap(vec[u], vec[v]);
        for(auto& p : vec[v]){
            if(vec[u].count(target-p.first)){
                ans = min(ans, vec[u][target-p.first]+p.second-2*dist[u]);
            }
        }
        for(auto& p : vec[v]){
            if(!vec[u].count(p.first)) vec[u].insert(p);
            else vec[u][p.first] = min(vec[u][p.first], p.second);
        }
    }
}


int best_path(int _n, int _k, int edges[][2], int weights[]) {
    if (k == 1) { return 0; }
    n = _n;
    k = _k;
    ans = INT_MAX;
    for (int i = 0; i < n - 1; i++) {
        int u = edges[i][0];
        int v = edges[i][1];
        G[u].pb(pii(v, weights[i]));
        G[v].pb(pii(u, weights[i]));
    }
    dfs0(0, -1);
    dfs(0, -1);
    return ans == INT_MAX ? -1 : ans;
}

Compilation message

race.cpp: In function 'long long int best_path(long long int, long long int, long long int (*)[2], long long int*)':
race.cpp:56:14: error: 'class std::vector<std::array<long long int, 2> >' has no member named 'pb'
   56 |         G[u].pb(pii(v, weights[i]));
      |              ^~
race.cpp:56:17: error: 'pii' was not declared in this scope
   56 |         G[u].pb(pii(v, weights[i]));
      |                 ^~~
race.cpp:57:14: error: 'class std::vector<std::array<long long int, 2> >' has no member named 'pb'
   57 |         G[v].pb(pii(u, weights[i]));
      |              ^~