Submission #900584

#TimeUsernameProblemLanguageResultExecution timeMemory
900584mayankfrostRace (IOI11_race)C++17
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 'void solve()':
race.cpp:113:11: warning: unused variable 'j' [-Wunused-variable]
  113 |     ll i, j, n, u, v, c;
      |           ^
/usr/bin/ld: /tmp/cc95cmBh.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccaoqyeh.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccaoqyeh.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