Submission #900580

#TimeUsernameProblemLanguageResultExecution timeMemory
900580mayankfrost경주 (Race) (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

typedef int ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;

#define N 200'005
#define L 1'000'005
#define MOD 1000000007
#define FOR(i, n) for (i = 0; i < n; i++)
#define FORR(i, a, b) for (i = a; i <= b; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define FREOPEN                        \
    freopen("yinyang.in", "r", stdin); \
    freopen("yinyang.out", "w", stdout);
#define gohome      \
    cout << "NO\n"; \
    return;
#define arprt(x)           \
    for (auto it : x)      \
        cout << it << " "; \
    cout << "\n";

void solve();

vpll edges[N];
vll torem;
ll sz[N], maxd, l, ans, cnt[L];
bool rem[N], calc;

const int BUF = 100'001;

ll find_sz(ll v, ll p)
{
    sz[v] = 1;
    for (auto [it, x] : edges[v])
        if (it != p && !rem[it])
            sz[v] += find_sz(it, v);
    return sz[v];
}

ll get_centroid(ll v, ll p, ll trsz)
{
    for (auto [it, x] : edges[v])
        if (it != p && !rem[it] && sz[it] * 2 > trsz)
            return get_centroid(it, v, trsz);
    return v;
}

void process(ll v, ll p, ll s, ll d)
{
    if (s > l)
        return;
    torem.push_back(s);
    if (calc)
    {
        if (cnt[l - s] < INT_MAX)
            ans = min(ans, d + cnt[l - s]);
    }
    else
        cnt[s] = min(cnt[s], d);
    for (auto [u, c] : edges[v])
    {
        if (u == p || rem[u])
            continue;
        process(u, v, s + c, d + 1);
    }
}

void centroid_decomp(ll v)
{
    ll centroid = get_centroid(v, -1, find_sz(v, -1));
    rem[centroid] = true;
    for (auto [u, c] : edges[centroid])
    {
        if (rem[u])
            continue;
        calc = true;
        process(u, -1, c, 1);
        calc = false;
        process(u, -1, c, 1);
    }
    for (auto it : torem)
        cnt[it] = INT_MAX;
    torem.clear();
    for (auto [it, x] : edges[centroid])
        if (!rem[it])
            centroid_decomp(it);
}

int main()
{
    FASTIO
    // FREOPEN
    int T;
    T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

void solve()
{
    ll i, j, n, u, v, c;
    cin >> n >> l;
    FOR(i, n - 1)
    {
        cin >> u >> v >> c;
        u--, v--;
        edges[u].push_back({v, c});
        edges[v].push_back({u, c});
    }
    for (i = 1; i < L; i++)
        cnt[i] = INT_MAX;
    centroid_decomp(0);
    if (ans == INT_MAX)
        ans = -1;
    cout << ans;
}

Compilation message (stderr)

race.cpp: In function 'll find_sz(ll, ll)':
race.cpp:42:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |     for (auto [it, x] : edges[v])
      |               ^
race.cpp: In function 'll get_centroid(ll, ll, ll)':
race.cpp:50:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |     for (auto [it, x] : edges[v])
      |               ^
race.cpp: In function 'void process(ll, ll, ll, ll)':
race.cpp:68:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |     for (auto [u, c] : edges[v])
      |               ^
race.cpp: In function 'void centroid_decomp(ll)':
race.cpp:80:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |     for (auto [u, c] : edges[centroid])
      |               ^
race.cpp:92:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   92 |     for (auto [it, x] : edges[centroid])
      |               ^
race.cpp: In function 'void solve()':
race.cpp:113:11: warning: unused variable 'j' [-Wunused-variable]
  113 |     ll i, j, n, u, v, c;
      |           ^
/usr/bin/ld: /tmp/ccqbwqLt.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccbg3itt.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccbg3itt.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