Submission #1121410

#TimeUsernameProblemLanguageResultExecution timeMemory
1121410namprozzRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int MAXN = 200005;

int n;
ll k;
vector<pair<int, ll>> adj[MAXN];

int child[MAXN];
bool marked[MAXN];
void countChild(int u, int p)
{
    child[u] = 1;
    for(auto [v, w] : adj[u])
    {
        if(v == p or marked[v])
            continue;
        countChild(v, u);
        child[u] += child[v];
    }
}

int findCentroid(int u, int p, int n)
{
    for(auto [v, w] : adj[u])
    {
        if(v == p or marked[v])
            continue;
        if(child[v] > n / 2)
        {
            return findCentroid(v, u, n);
        }
    }
    return u;
}

unordered_map<ll, ll> dp;
void dfs(int u, int p, ll tong)
{
    if(tong > k)
        return;
    dp[tong]++;
    for(auto [v, w] : adj[u])
    {
        if(v == p or marked[v])
            continue;
        dfs(v, u, tong + w);
    }
}

ll res = 0;

void decomp(int u)
{
    countChild(u, -1);
    int c = findCentroid(u, -1, child[u]);
    marked[c] = true;

    dp.clear();
    dfs(c, -1, 0);
    for(auto [tong, dem] : dp)
    {
        if(dp.count(k - tong))
        {
            res += dem * dp[k - tong];
        }
    }

    for(auto [v, w] : adj[c])
    {
        if(marked[v])
            continue;
        decomp(v);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    for(int i = 0; i < n - 1; i++)
    {
        int u, v;
        ll w;
        cin >> u >> v >> w;

        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    fill(marked, marked + n, false);
    decomp(0);
    if(res == 0)
    {
        cout << -1 << '\n';
    }
    else
    {
        cout << res << '\n';
    }
}

Compilation message (stderr)

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