제출 #739890

#제출 시각아이디문제언어결과실행 시간메모리
739890vjudge1경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
/*
Free at last, Free at last, Thank God Almighty, We are free at last.
*/

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#define ll long long
#define nl cout << '\n'
#define pri(n) cout<<fixed<<setprecision(n)
#define d5l_arr(arr, n) for(int i = 0 ; i < n ; i ++)cin >> arr[i]
const
double eps = -1e-9;
//const long double pi = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
const int inf = 1e9 + 1;
const int N = 2e5 + 1;


void m4_htgeb_tle_kda_ya3ny() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);
    cout.sync_with_stdio(0);
}

int ans = inf, n, k;

vector<pair<int, int>> adj[N];

map<ll, int> dfs(int u, int p, ll w, int dep) {
    map<ll, int> leader, other_leader;
    leader[w] = dep;
    for (auto v: adj[u]) {
        if (v.first == p)continue;
        other_leader = dfs(v.first, u, w + v.second, dep + 1);
        if (other_leader.size() > leader.size())swap(leader, other_leader);
        if (other_leader.count(k + w))ans = min(ans, (other_leader[k + w] - dep));
        for (auto el: other_leader) {
            ll rem = el.first - w;
            ll look_for = (k - rem) + w;
            if (leader.count(look_for))ans = min(ans, (el.second - dep) + (leader[look_for] - dep));
        }
        for (auto el: other_leader)leader.insert(el);
        other_leader.clear();
    }
    return leader;
}


void solveCase() {
    cin >> n >> k;
    vector<int> edges[n - 1];
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        edges[i].push_back(u);
        edges[i].push_back(v);
    }
    for (int i = 0; i < n - 1; ++i) {
        int w;
        cin >> w;
        adj[edges[i][0]].emplace_back(edges[i][1], w);
        adj[edges[i][1]].emplace_back(edges[i][0], w);
    }
    dfs(0, 0, 0, 0);
    cout << ((ans < inf) ? ans : -1);
}


int main() {
    m4_htgeb_tle_kda_ya3ny();
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; ++i) {
        solveCase();
        nl;
    }
    return 0;
}





컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccYCXoTR.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc49s2MS.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc49s2MS.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