답안 #1086422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086422 2024-09-10T14:51:23 Z ehab_rafat 경주 (Race) (IOI11_race) C++17
컴파일 오류
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;


const int N = 2e5+5;
std::vector<array<int,2>> G[N];
map<ll, ll> vec[N];
ll 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){
    ll 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], vector<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].push_back({v, weights[i]});
        G[v].push_back({u, weights[i]});
    }
    dfs0(0, -1);
    dfs(0, -1);
    return ans == INT_MAX ? -1 : ans;
}

Compilation message

/usr/bin/ld: /tmp/ccrtNpdC.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status