I tried following the editorial to come up with a solution to the Tree House problem in the May Long Challenge 2021. Can anyone help me figure out how I can further refine my code to pass the last two cases. The problem and solution I came up with is given below:
#define MOD 1000000007
using namespace std;
typedef unsigned long long ull;
ull solve(ull v, ull parent, vector<vector<ull>>& tree)
for (ull u: tree[v])
if (u != parent)
vals.push_back(solve(u, v, tree));
ull ret = 1;
ull mult = 1;
for (ull u: vals)
ret += (mult++)*u;
ull t; cin>>t;
ull n, x; cin>>n>>x;
for (ull i = 0; i < n - 1; ++i)
ull u, v;
tree[u - 1].push_back(v - 1);
tree[v - 1].push_back(u - 1);
cout<<(solve(0, -1, tree) % MOD * x % MOD)%MOD<<"\n";
Can you find the mistake yourself?
Oh so basically, the final product could overflow. Thanks a lot, man.
how do u put the code like?