Submission #1096191

#TimeUsernameProblemLanguageResultExecution timeMemory
1096191SunbaePutovanje (COCI20_putovanje)C++17
110 / 110
50 ms41412 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 2e5 + 5, M = 4e5 + 5; vector<int> g[N]; tuple<int,int,int,int> e[N]; int E[M], T[M], mn[N], ST[M][20], m; ll d[N]; void dfs(int u){ E[m++] = u; for(int v: g[u]){ g[v].erase(find(g[v].begin(), g[v].end(), u)); dfs(v); E[m++] = u; } } int get_lca(int u, int v){ if(mn[u] > mn[v]) swap(u, v); int j = 31 - __builtin_clz(mn[v] - mn[u] + 1); return T[min(ST[mn[u]][j], ST[mn[v]-(1<<j)+1][j])]; } void efs(int u){ for(int v: g[u]) efs(v), d[u] += d[v]; } signed main(){ int n; scanf("%d", &n); for(int i = 0, u, v, w[2]; i<n-1; ++i){ scanf("%d %d %d %d", &u, &v, w, w+1); --u; --v; g[u].push_back(v); g[v].push_back(u); e[i] = {u, v, w[0], w[1]}; } dfs(0); for(int i = m-1; i>=0; --i) T[mn[E[i]] = i] = E[i]; for(int i = 0; i<m; ++i) ST[i][0] = mn[E[i]]; for(int j = 1; j<32 - __builtin_clz(m); ++j) for(int i = 0; i+(1<<j)-1<m; ++i) ST[i][j] = min(ST[i][j-1], ST[i+(1<<(j-1))][j-1]); for(int i = 0; i<n-1; ++i){ int u = i, v = i+1, lca = get_lca(u, v); ++d[u]; ++d[v]; d[lca] -= 2; } efs(0); ll tot = 0; for(int i = 0, u, v, w[2]; i<n-1; ++i){ tie(u, v, w[0], w[1]) = e[i]; if(mn[u] > mn[v]) swap(u, v); tot += min(w[0] * 1ll * d[v], 1ll * w[1]); } printf("%lld", tot); }

Compilation message (stderr)

putovanje.cpp: In function 'int main()':
putovanje.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
putovanje.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d %d %d %d", &u, &v, w, w+1); --u; --v;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...