제출 #111406

#제출 시각아이디문제언어결과실행 시간메모리
111406diamond_dukeFireworks (APIO16_fireworks)C++11
100 / 100
609 ms16504 KiB
#include <algorithm> #include <cstdio> using ll = long long; int lson[1200005], rson[1200005], dep[1200005], t_cnt; ll val[1200005]; int merge(int u, int v) { if (!u || !v) return u | v; if (val[u] < val[v]) std::swap(u, v); rson[u] = merge(rson[u], v); if (dep[lson[u]] < dep[rson[u]]) std::swap(lson[u], rson[u]); dep[u] = rson[u] ? dep[rson[u]] + 1 : 0; return u; } inline int new_node(ll x) { val[++t_cnt] = x; return t_cnt; } void pop(int &u) { u = merge(lson[u], rson[u]); } int fa[600005], faw[600005], deg[600005], rt[600005]; int main() { // freopen("uoj-205.in", "r", stdin); int n, m; scanf("%d%d", &n, &m); ll ans = 0; for (int i = 1; i < n + m; i++) { scanf("%d%d", fa + i, faw + i); deg[--fa[i]]++; ans += faw[i]; } for (int u = n + m - 1; u; u--) { ll l = 0, r = 0; if (u < n) { while (--deg[u]) pop(rt[u]); r = val[rt[u]]; pop(rt[u]); l = val[rt[u]]; pop(rt[u]); } rt[u] = merge(rt[u], merge(new_node(l + faw[u]), new_node(r + faw[u]))); rt[fa[u]] = merge(rt[fa[u]], rt[u]); } while (deg[0]--) pop(rt[0]); while (rt[0]) { ans -= val[rt[0]]; pop(rt[0]); } printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

fireworks.cpp: In function 'int main()':
fireworks.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", fa + i, faw + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...