Submission #597317

#TimeUsernameProblemLanguageResultExecution timeMemory
597317ThegeekKnight16Arboras (RMI20_arboras)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAXN = 1e5 + 10; vector<int> grafo[MAXN]; vector<ll> pesos[MAXN]; int indices[MAXN]; int pai[MAXN]; ll dp[MAXN][2]; int filho[MAXN][2]; ll modulo = 1e9 + 7; void dfs(int v) { dp[v][0] = 0LL; dp[v][1] = 0LL; filho[v][0] = -1; filho[v][1] = -1; for (int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; ll 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); filho[v][1] = filho[v][0]; filho[v][0] = viz; } else if (dp[viz][0] + p >= dp[v][1]) { dp[v][1] = (dp[viz][0] + p); filho[v][1] = viz; } } } 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++) { ll p; cin >> p; pesos[pai[i]].push_back(p); indices[i] = pesos[pai[i]].size()-1; } int Q; cin >> Q; dfs(0); ll resp = 0; for (int i = 0; i < N; i++) {resp += (dp[i][0] + dp[i][1]) % (modulo); resp = resp % modulo;} cout << resp; for (int q = 1; q <= Q; q++) { int v; ll add; cin >> v >> add; pesos[pai[v]][indices[v]] += add; while (v != 0) { ll p = pesos[pai[v]][indices[v]]; /*cerr << "Estou no " << v << " com add " << add << '\n';*/ //if (dp[v][0] + p <= dp[pai[v]][1]) {/*cerr << "Nao era grande ent quebrei" << '\n';*/ break;} if (v == filho[pai[v]][0]) { /*cerr << "Eu era o filho 0";*/ if (dp[pai[v]][0] == dp[v][0] + p) {/*cerr << "mas n mudei nada" << '\n';*/ break;} /*cerr << '\n';*/ resp += max(0, dp[pai[v]][0] - (dp[v][0] + p)); resp = resp % modulo; dp[pai[v]][0] = max(dp[pai[v]][0], dp[v][0] + p); //resp += (add) % modulo; //resp = resp % modulo; } else if (v == filho[pai[v]][1]) { /*cerr << "Eu era o filho 1";*/ //if (dp[pai[v]][1] == dp[v][0] + p) {/*cerr << "mas n mudei nada" << '\n';*/ break;} resp += max(0, dp[pai[v]][1] - (dp[v][0] + p)); resp = resp % modulo; dp[pai[v]][1] = max(dp[pai[v]][1], dp[v][0] + p); //resp += (add) % modulo; //resp = resp % modulo; if (dp[pai[v]][1] > dp[pai[v]][0]) { /*cerr << " e agr virei 0";*/ swap(filho[pai[v]][0], filho[pai[v]][1]); swap(dp[pai[v]][1], dp[pai[v]][0]); } /*cerr << '\n';*/ } else { /*cerr << "Eu n era filho, por isso aumentou em " << ((dp[v][0] + p) - dp[pai[v]][1]) << '\n';*/ //resp += ((dp[v][0] + p) - dp[pai[v]][1]) % modulo; //resp = resp % modulo; resp += max(0, dp[pai[v]][1] - (dp[v][0] + p)); resp = resp % modulo; if (dp[v][0] + p >= dp[pai[v]][0]) { dp[pai[v]][1] = dp[pai[v]][0]; dp[pai[v]][0] = (dp[v][0] + p); filho[pai[v]][1] = filho[pai[v]][0]; filho[pai[v]][0] = v; } else if (dp[v][0] + p >= dp[pai[v]][1]) { dp[pai[v]][1] = (dp[v][0] + p); filho[pai[v]][1] = v; } } v = pai[v]; } cout << '\n' << resp; } }

Compilation message (stderr)

arboras.cpp: In function 'void dfs(int)':
arboras.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < grafo[v].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
arboras.cpp: In function 'int main()':
arboras.cpp:79:61: error: no matching function for call to 'max(int, ll)'
   79 |                resp += max(0, dp[pai[v]][0] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
arboras.cpp:79:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   79 |                resp += max(0, dp[pai[v]][0] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
arboras.cpp:79:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   79 |                resp += max(0, dp[pai[v]][0] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
arboras.cpp:79:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   79 |                resp += max(0, dp[pai[v]][0] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
arboras.cpp:79:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   79 |                resp += max(0, dp[pai[v]][0] - (dp[v][0] + p));
      |                                                             ^
arboras.cpp:89:61: error: no matching function for call to 'max(int, ll)'
   89 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
arboras.cpp:89:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   89 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
arboras.cpp:89:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   89 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
arboras.cpp:89:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   89 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
arboras.cpp:89:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   89 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
arboras.cpp:107:61: error: no matching function for call to 'max(int, ll)'
  107 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
arboras.cpp:107:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  107 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
arboras.cpp:107:61: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  107 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
arboras.cpp:107:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  107 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from arboras.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
arboras.cpp:107:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  107 |                resp += max(0, dp[pai[v]][1] - (dp[v][0] + p));
      |                                                             ^