Submission #1025012

#TimeUsernameProblemLanguageResultExecution timeMemory
1025012yellowtoadPower Plant (JOI20_power)C++17
100 / 100
219 ms30284 KiB
#include <iostream> #include <vector> using namespace std; int n, dp[200010], b[200010], dpp[200010], ans; vector<int> edge[200010]; char ch; void dfs(int u, int v) { for (int i = 0; i < edge[u].size(); i++) { if (edge[u][i] != v) { dfs(edge[u][i],u); dp[u] += dp[edge[u][i]]; } } if (b[u]) dp[u] = max(dp[u]-1,1); } void dfs1(int u, int v, int maxx) { int sum = 0; dpp[u] = dp[u]+maxx; for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) sum += dp[edge[u][i]]; for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs1(edge[u][i],u,(b[u] ? max(maxx+sum-dp[edge[u][i]]-1,1) : maxx+sum-dp[edge[u][i]])); } int main() { cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; edge[u].push_back(v); edge[v].push_back(u); } for (int i = 1; i <= n; i++) { cin >> ch; b[i] = ch-'0'; } dfs(1,0); dfs1(1,0,0); for (int i = 1; i <= n; i++) ans = max(ans,dpp[i]); cout << ans << endl; }

Compilation message (stderr)

power.cpp: In function 'void dfs(int, int)':
power.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < edge[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
power.cpp: In function 'void dfs1(int, int, int)':
power.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) sum += dp[edge[u][i]];
      |                  ~~^~~~~~~~~~~~~~~~
power.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs1(edge[u][i],u,(b[u] ? max(maxx+sum-dp[edge[u][i]]-1,1) : maxx+sum-dp[edge[u][i]]));
      |                  ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...