Submission #597214

#TimeUsernameProblemLanguageResultExecution timeMemory
597214ThegeekKnight16Arboras (RMI20_arboras)C++14
0 / 100
5058 ms13772 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; vector<int> grafo[MAXN], pesos[MAXN]; int indices[MAXN]; int pai[MAXN], dp[MAXN][2]; int modulo = 1e9 + 7; void dfs(int v) { dp[v][0] = 0; dp[v][1] = 0; for (int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; int p = pesos[v][i]; dfs(viz); if (dp[viz][0] + p >= dp[v][0]) { dp[v][1] = dp[v][0]; dp[v][0] = (dp[viz][0] + p) % (modulo); } else if (dp[viz][0] + p >= dp[v][1]) dp[v][1] = (dp[viz][0] + p) % (modulo); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; for (int i = 1; i < N; i++) { cin >> pai[i]; grafo[pai[i]].push_back(i); } for (int i = 1; i < N; i++) { int p; cin >> p; pesos[pai[i]].push_back(p); indices[i] = pesos[pai[i]].size()-1; } int Q; cin >> Q; dfs(0); int resp = 0; for (int i = 0; i < N; i++) {resp += (dp[i][0] + dp[i][1]) % (modulo); resp = resp % modulo;} cout << resp << '\n'; for (int q = 1; q <= Q; q++) { int v, add; cin >> v >> add; pesos[pai[v]][indices[v]] += add; dfs(0); resp = 0; for (int i = 0; i < N; i++) {resp += (dp[i][0] + dp[i][1]) % (modulo); resp = resp % modulo;} cout << resp << '\n'; } }

Compilation message (stderr)

arboras.cpp: In function 'void dfs(int)':
arboras.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < grafo[v].size(); 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...