Submission #62722

# Submission time Handle Problem Language Result Execution time Memory
62722 2018-07-29T21:57:28 Z eriksuenderhauf Race (IOI11_race) C++11
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3")
#include "grader.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
vii adj[MAXN];
int ans = INF, sz[MAXN], vis[MAXN], n, k;

void getSz(int u, int p)
{
    sz[u] = 1;
    for (pii v: adj[u])
        if (v.fi != p && !vis[v.fi])
        {
            getSz(v.fi, u);
            sz[u] += sz[v.fi];
        }
}

int findCen(int u, int p, int n)
{
    for (pii v: adj[u])
        if (v.fi != p && !vis[v.fi] && sz[v.fi] > n / 2)
            return findCen(v.fi, u, n);
    return u;
}

ht cnt, cnt2;

void add(int u, int p, int d, int w)
{
    if (w == k)
        ans = min(ans, d);
    w = min(w, INF);
    if (cnt.find(w) == cnt.end())
        cnt[w] = INF;
    cnt[w] = min(cnt[w], d);
    if (cnt2.find(k - w) != cnt2.end())
        ans = min(ans, cnt2[k - w] + d);
    for (pii v: adj[u])
        if (v.fi != p && !vis[v.fi])
            add(v.fi, u, d + 1, w + v.se);
}

void join(int u, int p, int d, int w)
{
    w = min(w, INF);
    if (cnt2.find(w) == cnt2.end())
        cnt2[w] = INF;
    cnt2[w] = min(cnt2[w], d);
    for (pii v: adj[u])
        if (v.fi != p && !vis[v.fi])
            join(v.fi, u, d + 1, w + v.se);
}

void decompose(int u)
{
    getSz(u, -1);
    int c = findCen(u, -1, sz[u]);
    vis[c] = 1;
    for (pii v: adj[c])
        if (!vis[v.fi])
            decompose(v.fi);
    for (pii v: adj[c])
    {
        if (vis[v.fi])
            continue;
        add(v.fi, c, 1, v.se);
        join(v.fi, c, 1, v.se);
        cnt.clear();
    }
    cnt2.clear();
    vis[c] = 0;
}

int best_path(int N, int K, int H[][2], int L[]){
    n = N, k = K;
    for (int i = 1; i < n; i++)
    {
        int u = H[i-1][0], v = H[i-1][1], w = L[i-1];
        u--, v--;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    decompose(0);
    if (ans == INF)
        ans = -1;
    return ans;
}

/*int main()
{
    ni(n), ni(k);
    for (int i = 1; i < n; i++)
    {
        int u, v, w;
        ni(u), ni(v), ni(w);
        u--, v--;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    decompose(0);
    if (ans == INF)
        ans = -1;
    pri(ans);
    return 0;
}*/

Compilation message

race.cpp:2:10: fatal error: grader.h: No such file or directory
 #include "grader.h"
          ^~~~~~~~~~
compilation terminated.