Submission #763283

#TimeUsernameProblemLanguageResultExecution timeMemory
763283vjudge1Power Plant (JOI20_power)C++17
100 / 100
120 ms26572 KiB
#include <bits/stdc++.h> using namespace std; const int NM = 2e5; int N, plant[NM+5], dp[NM+5], ans = 0; vector <int> adj[NM+5]; void DFS(int u, int par){ int tmp = 0; for (int i = 0; i < adj[u].size(); i++){ int v = adj[u][i]; if (v == par) continue; DFS(v, u); dp[u] += dp[v]; tmp = max(tmp, dp[v]); } dp[u] -= plant[u]; dp[u] = max(dp[u], plant[u]); ans = max(ans, dp[u]); ans = max(ans, tmp+plant[u]); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (int i = 1; i < N; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= N; i++){ char ch; cin >> ch; plant[i] = ch-'0'; } DFS(1, 1); cout << ans; return 0; }

Compilation message (stderr)

power.cpp: In function 'void DFS(int, int)':
power.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for (int i = 0; i < adj[u].size(); i++){
      |                  ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...