Блог пользователя cs2_ak47

Автор cs2_ak47, история, 21 час назад, По-русски

Why my this solution giving runtime error?


#include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define all(v) v.begin(), v.end() #define nl cout << "\n" #define co(a) { cout << a << ' '; } #define cou(a) { cout << a << "\n"; } #define lcou(v) { for (auto& x : v) co(x); nl } #define cy(x) { if(x) cou("YES") else cou("NO") } const int M = 1e9 + 7; const int N = 5010; ll n, targ[N][N]; ll inf = 1e18; vector<ll> e[N]; ll a[N], ans[N]; void dfs(ll x) { if (e[x].empty()) { for (int i = 1; i <= n; i++) { targ[x][i] = inf; } ans[x] = 0; return; } ll sums = 0; ans[x] = 0; for (auto j : e[x]) { dfs(j); ans[x] += ans[j]; sums += a[j]; } ll del = a[x] - sums; for (int i = 1; i <= n; i++) { if (del <= 0) break; for (auto j : e[x]) { if (del <= 0) break; if (targ[j][i] <= del) { ans[x] += i * targ[j][i]; del -= targ[j][i]; targ[j][i] = 0; } else { ans[x] += i * del; targ[j][i] -= del; del = 0; } } } if (del < 0) targ[x][1] = -del; for (int i = 2; i <= n; i++) { ll nsum = 0; for (auto j : e[x]) { if (targ[j][i - 1] == inf) { nsum = inf; break; } nsum += targ[j][i - 1]; } targ[x][i] = nsum; } } void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; e[i].clear(); } for (int i = 1; i <= n; i++) { ans[i] = 0; for (int j = 1; j <= n; j++) { targ[i][j] = 0; } } for (int i = 2; i <= n; i++) { ll f; cin >> f; e[f].push_back(i); } dfs(1); cou(ans[1]); } signed main() { int TC; cin >> TC; while (TC--) { solve(); } return TC; }

Can someone explain this to me, last 5 minutes i tried to submit but it is giving Runtime error

Полный текст и комментарии »

  • Проголосовать: нравится
  • -1
  • Проголосовать: не нравится

Автор cs2_ak47, история, 13 дней назад, По-русски

These days I heard a lot of times word "Luogu". So can you explain me what's Luogu?

sorry for my poor English(

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор cs2_ak47, история, 13 дней назад, По-русски

Hi team. How you know I got 920 rating at 4 contests. I think it is good for me so I want to reach Specialist with minimum number of contests. Can you tell me some algorithms in CP to learn that will be enough to reach Specialist?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится