Submission #242273

#TimeUsernameProblemLanguageResultExecution timeMemory
242273tqbfjotldMagic Tree (CEOI19_magictree)C++14
14 / 100
86 ms8056 KiB
/* subtask 1 - brute force subtask 2 - take all subtask 3 - lds subtask 4 - dp on tree, day1-day2 */ #include <bits/stdc++.h> using namespace std; int n,m,k; int p[100005]; int d[100005]; long long w[100005]; vector<int> adjl[100005]; long long tot[100005]; long long func(int node){ if (adjl[node].size()==0){ tot[node] = d[node]==1?w[node]:-w[node]; return max(0LL,tot[node]); } long long ans = 0; for (auto x : adjl[node]){ ans += func(x); tot[node] += tot[x]; } tot[node] += d[node]==1?w[node]:-w[node]; return max(ans,tot[node]); } int main(){ scanf("%d%d%d",&n,&m,&k); bool subtask3 = true; for (int x = 1; x<n; x++){ scanf("%d",&p[x]); p[x]--; if (p[x]!=x-1) subtask3 = false; adjl[p[x]].push_back(x); } long long temps=0; for (int x = 0; x<m; x++){ int a,b; long long c; scanf("%d%d%lld",&a,&b,&c); a--; d[a] = b; w[a] = c; if (w[a]!=1) subtask3 = false; if (d[x]==2) temps+=w[x]; } if (k<=2){ printf("%lld",func(0)+temps); } else if (subtask3){ vector<int> v; for (int x = 0; x<n; x++){ if (w[x]==0) continue; if (v.empty()) v.push_back(-d[x]); else if (-d[x]>=v[(int)v.size()-1]){ v.push_back(-d[x]); } else{ int pos = upper_bound(v.begin(),v.end(),-d[x])-v.begin(); v[pos] = -d[x]; } } printf("%d",v.size()); } else{ long long ans = 0; for (int x = 0; x<n; x++){ ans += w[x]; } printf("%lld",ans); } }

Compilation message (stderr)

magictree.cpp: In function 'int main()':
magictree.cpp:71:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
         printf("%d",v.size());
                     ~~~~~~~~^
magictree.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
magictree.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&p[x]);
         ~~~~~^~~~~~~~~~~~
magictree.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...