From 12ab34e7a4f99ec54d7b74ca5f561b6b0078f520 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 21 Oct 2024 20:22:23 +0800 Subject: [PATCH] update --- src/20241019/confess/confess_after.cpp | 21 ++++- src/P1351/P1351.cpp | 112 +++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/P1351/P1351.cpp diff --git a/src/20241019/confess/confess_after.cpp b/src/20241019/confess/confess_after.cpp index 48203f2..39d856d 100644 --- a/src/20241019/confess/confess_after.cpp +++ b/src/20241019/confess/confess_after.cpp @@ -19,16 +19,33 @@ int main(){ std::cin>>s; ll odd_add_num{}; //奇数+ -> -2 ll even_sub_num{};//偶数- -> +2 + /* + 奇数->(bin*1) + 偶数->(bin*0) + 不坦白-> + +1 + -1 + ->不论怎样,奇偶性质都会改变 + + 坦白-> + 原本是'+' + 奇数(*1)->xor 1->*0 -2 + 偶数(*0)->xor 1->*1 0 + 原本是'-' + 奇数(*1)->xor 1->*0 0 + 偶数(*0)->xor 1->*1 +2 + + */ ll sum{}; for(ll i{0};i +#include +#include +#include + +using ll = long long; + +const ll max_n = 2e5+5; +const ll MOD = 10007; +ll n, w[max_n]; + +std::vector next[max_n]; +ll brothers_from_father[max_n]; + +ll ans_max,ans_sum; + +#ifdef ONLINE_JUDGE + #define DEBUG(code) +#else + #define DEBUG(code)code +#endif + +DEBUG( + template + void debug(Args&&...args){ + std::cout<<"[DEBUG]: "; + (std::cout<<...<(args)); + std::cout<<'\n'; + } +) + +void dfs(const ll now, const ll father,const ll grand_father){ + if(father == -1){ + for(const auto i:next[now]){ + if(i==father)continue; + dfs(i, now,-1); + } + return; + }else if(grand_father == -1){ + for(const auto i:next[now]){ + if(i==father)continue; + dfs(i,now,father); + } + return; + } + + DEBUG( + debug("args: ",now," ",father," ",grand_father); + ) + if(!next[now].empty()){ + for (const auto i: next[now]) { + if(i==father)continue; + dfs(i,now,father); + } + } + for(const auto i : next[father]){ + if(i != now){ + ans_max = std::max(ans_max, w[i]*w[now]); + DEBUG( + debug("update max ",ans_max); + ) + DEBUG( + debug("brother: ",w[i],' ',w[now]); + ) + brothers_from_father[father] = ((w[i]*w[now]) % MOD + brothers_from_father[father]) % MOD; + } + } + DEBUG( + debug(w[now],' ',w[grand_father]); + ) + ans_max = std::max(ans_max, w[now] * w[grand_father]); + DEBUG( + debug("update max ",ans_max); + ) + ans_sum = (ans_sum + (w[now]*w[grand_father]) % MOD) % MOD; +} + +int main(){ + std::cin>>n; + for(ll i{1};i>a>>b; + next[a].push_back(b); + next[b].push_back(a); + } + for(ll i{1};i<=n;i++){ + std::cin>>w[i]; + } + dfs(1, -1, -1); + + for(ll i{1};i<=n;i++){ + DEBUG( + debug("from brother ",i," add :",brothers_from_father[i]); + ) + ans_sum = (ans_sum + brothers_from_father[i]) % MOD; + } + + std::cout<