Submission #986406

#TimeUsernameProblemLanguageResultExecution timeMemory
986406Neco_arcCat in a tree (BOI17_catinatree)C++17
100 / 100
373 ms263880 KiB
#include <bits/stdc++.h> //#include <bits/debug.hpp> #define ll long long #define all(x) x.begin(), x.end() #define Neco "Maximum Weight Subset" #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 2e5 + 7 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; int n, k; int a[maxn]; vector<int> edges[maxn]; deque<int> dp[maxn]; void dfs(int u, int par) { dp[u] = {1}; for(int v : edges[u]) if(v != par) { dfs(v, u); if(dp[u].size() < dp[v].size()) swap(dp[u], dp[v]); fi(i, 0, dp[v].size() - 1) { int x = max(k - i, i); int w1 = dp[v][i] + (x < dp[u].size() ? dp[u][x] : 0); int w2 = dp[u][i] + (x < dp[v].size() ? dp[v][x] : 0); dp[u][i] = max({dp[u][i], w1, w2}); } fid(i, dp[v].size() - 1, 0) { if(i + 1 < dp[u].size()) dp[u][i] = max(dp[u][i], dp[u][i + 1]); } } dp[u].push_front(dp[u].front()); } void solve() { cin >> n >> k; fi(i, 2, n) { int x; cin >> x, ++x; edges[x].push_back(i); } dfs(1, 0); cout << dp[1][0]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

catinatree.cpp: In function 'void dfs(int, int)':
catinatree.cpp:12:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define fi(i, a, b) for(int i = a; i <= b; i++)
......
   33 |         fi(i, 0, dp[v].size() - 1) {
      |            ~~~~~~~~~~~~~~~~~~~~~~     
catinatree.cpp:33:9: note: in expansion of macro 'fi'
   33 |         fi(i, 0, dp[v].size() - 1) {
      |         ^~
catinatree.cpp:35:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             int w1 = dp[v][i] + (x < dp[u].size() ? dp[u][x] : 0);
      |                                  ~~^~~~~~~~~~~~~~
catinatree.cpp:36:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             int w2 = dp[u][i] + (x < dp[v].size() ? dp[v][x] : 0);
      |                                  ~~^~~~~~~~~~~~~~
catinatree.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             if(i + 1 < dp[u].size()) dp[u][i] = max(dp[u][i], dp[u][i + 1]);
      |                ~~~~~~^~~~~~~~~~~~~~
catinatree.cpp: In function 'int main()':
catinatree.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
catinatree.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...