Submission #1320387

#TimeUsernameProblemLanguageResultExecution timeMemory
1320387ThanhsRace (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include "race.h"#include <bits/stdc++.h>
using namespace std;

#define name "TENBAI"
#define fi first
#define se second
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()

const int inf = 1e9;
const int NM = 2e5 + 5;

vector<pair<int, int>> g[NM];
int n, k, ans = inf, done[NM], sz[NM];
map<int, int> mp;

int dfs_sz(int u, int p)
{
    sz[u] = 1;
    for (auto v : g[u])
        if (v.fi != p && !done[v.fi])
            sz[u] += dfs_sz(v.fi, u);
    return sz[u];
}

int findcen(int u, int p, int SZ)
{
    for (auto v : g[u])
        if (v.fi != p && !done[v.fi] && 2 * sz[v.fi] >= SZ)
            return findcen(v.fi, u, SZ);
    return u;
}

void get(int u, int p, int w, int c)
{
    if (mp.count(k - w))
        setmin(ans, c + mp[k - w]);
    for (auto v : g[u])
        if (v.fi != p && !done[v.fi])
            get(v.fi, u, w + v.se, c + 1);
}

void add(int u, int p, int w, int c)
{
    if (mp.count(w))
        setmin(mp[w], c);
    else
        mp[w] = c;
    for (auto v : g[u])
        if (v.fi != p && !done[v.fi])
            get(v.fi, u, w + v.se, c + 1);
}

void cen(int u)
{
    int c = findcen(u, 0, dfs_sz(u, 0));
    mp.clear();
    mp[0] = 0;
    for (auto v : g[c])
        if (!done[v.fi])
        {
            get(v.fi, c, v.se, 1);
            add(v.fi, c, v.se, 1);
        }
    done[c] = 1;
    for (auto v : g[c])
        if (!done[v.fi])
            cen(v.fi);
    cout << endl;
}

int best_path(int N, int K, int H[][2], int L[])
{
    n = N; k = K;
    for (int i = 0; i < n - 1; i++)
    {
        g[H[i][0]].emplace_back(H[i][1], L[i]);
        g[H[i][1]].emplace_back(H[i][0], L[i]);
    }
    cen(0);
  return ans == inf ? -1 : ans;
}

Compilation message (stderr)

race.cpp:1:18: warning: extra tokens at end of #include directive
    1 | #include "race.h"#include <bits/stdc++.h>
      |                  ^
race.cpp:16:8: error: 'pair' was not declared in this scope
   16 | vector<pair<int, int>> g[NM];
      |        ^~~~
race.cpp:2:1: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
    1 | #include "race.h"#include <bits/stdc++.h>
  +++ |+#include <utility>
    2 | using namespace std;
race.cpp:16:8: error: 'pair' was not declared in this scope
   16 | vector<pair<int, int>> g[NM];
      |        ^~~~
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:8: error: 'pair' was not declared in this scope
race.cpp:16:8: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
race.cpp:16:1: error: 'vector' does not name a type
   16 | vector<pair<int, int>> g[NM];
      | ^~~~~~
race.cpp:18:1: error: 'map' does not name a type
   18 | map<int, int> mp;
      | ^~~
race.cpp: In function 'int dfs_sz(int, int)':
race.cpp:23:19: error: 'g' was not declared in this scope
   23 |     for (auto v : g[u])
      |                   ^
race.cpp: In function 'int findcen(int, int, int)':
race.cpp:31:19: error: 'g' was not declared in this scope
   31 |     for (auto v : g[u])
      |                   ^
race.cpp: In function 'void get(int, int, int, int)':
race.cpp:39:9: error: 'mp' was not declared in this scope; did you mean 'p'?
   39 |     if (mp.count(k - w))
      |         ^~
      |         p
race.cpp:8:26: error: 'min' was not declared in this scope
    8 | #define setmin(x, y) x = min((x), (y))
      |                          ^~~
race.cpp:40:9: note: in expansion of macro 'setmin'
   40 |         setmin(ans, c + mp[k - w]);
      |         ^~~~~~
race.cpp:41:19: error: 'g' was not declared in this scope
   41 |     for (auto v : g[u])
      |                   ^
race.cpp: In function 'void add(int, int, int, int)':
race.cpp:48:9: error: 'mp' was not declared in this scope; did you mean 'p'?
   48 |     if (mp.count(w))
      |         ^~
      |         p
race.cpp:8:26: error: 'min' was not declared in this scope
    8 | #define setmin(x, y) x = min((x), (y))
      |                          ^~~
race.cpp:49:9: note: in expansion of macro 'setmin'
   49 |         setmin(mp[w], c);
      |         ^~~~~~
race.cpp:52:19: error: 'g' was not declared in this scope
   52 |     for (auto v : g[u])
      |                   ^
race.cpp: In function 'void cen(int)':
race.cpp:60:5: error: 'mp' was not declared in this scope
   60 |     mp.clear();
      |     ^~
race.cpp:62:19: error: 'g' was not declared in this scope
   62 |     for (auto v : g[c])
      |                   ^
race.cpp:69:19: error: 'g' was not declared in this scope
   69 |     for (auto v : g[c])
      |                   ^
race.cpp:72:5: error: 'cout' was not declared in this scope
   72 |     cout << endl;
      |     ^~~~
race.cpp:2:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include "race.h"#include <bits/stdc++.h>
  +++ |+#include <iostream>
    2 | using namespace std;
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:80:9: error: 'g' was not declared in this scope
   80 |         g[H[i][0]].emplace_back(H[i][1], L[i]);
      |         ^