{"blog_url":"https://babcs2035.hateblo.jp/","version":"1.0","provider_name":"Hatena Blog","author_name":"babcs2035","url":"https://babcs2035.hateblo.jp/entry/2019/03/19/065905","title":"Codeforces Round #530 (Div. 1)\uff1aA. Sum in the tree","width":"100%","published":"2019-03-19 06:59:05","categories":["\u7af6\u6280\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0","Codeforces \u554f\u984c"],"type":"rich","image_url":"https://cdn-ak.f.st-hatena.com/images/fotolife/b/babcs2035/20190319/20190319065853.png","height":"190","provider_url":"https://hatena.blog","author_url":"https://blog.hatena.ne.jp/babcs2035/","description":"\u554f\u984c \u89e3\u6cd5 \u89e3\u7b54 \u554f\u984c codeforces.com \u89e3\u6cd5 b_i \u3092\u300c\u9802\u70b9 i \u3092\u6839\u3068\u3059\u308b\u5168\u3066\u90e8\u5206\u6728\u306b\u542b\u307e\u308c\u308b s \u306e\u6700\u5c0f\u5024\u300d\u3068\u304a\u304f\uff0e\u3053\u306e\u3068\u304d\uff0cb_i < s_i \u3067\u3042\u308b\u3088\u3046\u306a\u9802\u70b9\u304c\u5b58\u5728\u3057\u305f\u3089\u305d\u306e\u6728\u306f\u69cb\u6210\u4e0d\u53ef\u80fd\u306a\u306e\u3067 -1 \u3092\u51fa\u529b\u3059\u308c\u3070\u3088\u3044\uff0e \u6728\u304c\u69cb\u6210\u51fa\u6765\u308b\u5834\u5408\uff0c\u6728\u5168\u4f53\u3092\u6839\u304b\u3089\uff08\u3059\u306a\u308f\u3061\u9802\u70b9 1 \u304b\u3089\uff09\u898b\u3066\u3044\u304f\uff0e\u300cdfs(i, s) := \u4eca\u9802\u70b9 i \u3092\u898b\u3066\u3044\u3066\uff0c\u30d1\u30b9\u306b\u3042\u308b\u9802\u70b9\u306e a \u306e\u548c\u304c sum \u306e\u3068\u304d\u300d\u3068 DFS \u3092\u7acb\u3066\u3066\uff0ca_i = b_i - sum \u3068\u3059\u308c\u3070\u3088\u3044\uff0e\u3053\u308c\u3092\u5168\u3066\u306e\u9802\u70b9\u306b\u3064\u3044\u3066\u51e6\u7406\u3057 a \u3092\u6c42\u3081\u308c\u3070\u3088\u3044\uff0eO(N)\uff0e \u89e3\u7b54 codeforces.com","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fbabcs2035.hateblo.jp%2Fentry%2F2019%2F03%2F19%2F065905\" title=\"Codeforces Round #530 (Div. 1)\uff1aA. Sum in the tree - \u304d\u308d\u304f\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","blog_title":"\u304d\u308d\u304f"}