Submission #897815

#TimeUsernameProblemLanguageResultExecution timeMemory
897815ShaShiFactories (JOI14_factories)C++17
Compilation error
0 ms0 KiB
#include "factories.h" #include <bits/stdc++.h> #define int long long #define F first #define S second #define pii pair<int, int> #define all(x) x.begin(), x.end() #define kill(x) cout << x << endl, exit(0); #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int MAXN = (int)2e6 + 7; const int MOD = 998244353; const ll INF = (ll)1e18 + 7; ll n, m, t, k, q, u, v, w, tmp, tmp2, tmp3, tmp4, tmp5, ans2, flag; ll ans; ll arr[MAXN], sz[MAXN]; bool hate[MAXN]; pair<pair<ll, ll>, pair<ll, ll> > love[MAXN]; vector<pair<ll, ll> > adj[MAXN]; vector<pair<ll, ll> > vec[MAXN]; void DFSsz(int v, int p=-1) { sz[v] = 1; for (auto cur:adj[v]) { int u = cur.F; if (!hate[u] && u != p) { DFSsz(u, v); sz[v] += sz[u]; } } } int centroid(int tot, int v, int p=-1) { for (auto cur:adj[v]) { int u = cur.F; if (!hate[u] && u != p && 2*sz[u] > tot) return centroid(tot, u, v); } return v; } void all_i_want(int cent, int v, int p, ll dis) { for (auto cur:adj[v]) { ll u = cur.F, w = cur.S; if (!hate[u] && u != p) all_i_want(cent, u, v, dis+w); } vec[v].pb(mp(cent, dis)); } void solve(int v) { DFSsz(v); int cent = centroid(sz[v], v); hate[cent] = 1; for (auto cur:adj[cent]) { ll u = cur.F, w = cur.S; if (!hate[u]) all_i_want(cent, u, cent, w); } vec[cent].pb(mp(cent, 0ll)); for (auto cur:adj[cent]) { int u = cur.F; if (!hate[u]) solve(u); } } void add(int v, bool x=0) { for (auto cur:vec[v]) { int u = cur.F; ll w = cur.S; if (x) { if (love[u].F.S != flag) { love[u].F.S = flag; love[u].F.F = w; } else { love[u].F.F = min(love[u].F.F, w); } } else { if (love[u].S.S != flag) { love[u].S.S = flag; love[u].S.F = w; } else { love[u].S.F = min(love[u].S.F, w); } } if (love[u].F.S == love[u].S.S && love[u].S.S == flag) ans = min(ans, love[u].F.F+love[u].S.F); } } void Init(int N, int A[], int B[], int D[]) { n = N; for (int i=1; i<n; i++) { u = A[i-1], v = B[i-1], w = D[i-1]; u++, v++; adj[u].pb(mp(v, w)); adj[v].pb(mp(u, w)); } solve(1); } int Query(int SS, int X[], int T, int Y[]) { flag++; ans = INF; while (SS--) { cin >> u; u++; add(u, 0); } while (T--) { cin >> v; v++; add(v, 1); } return ans; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccBwBBGE.o: in function `main':
grader.cpp:(.text.startup+0x37d): undefined reference to `Init(int, int*, int*, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x412): undefined reference to `Query(int, int*, int, int*)'
collect2: error: ld returned 1 exit status