Submission #963804

# Submission time Handle Problem Language Result Execution time Memory
963804 2024-04-15T17:20:18 Z Trisanu_Das Power Plant (JOI20_power) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

string s;
vector<int> V[200005], dp(200005, 0);
bool vis[200005];
     
void dfs(int v, int root) {
   	vis[v] = 1;
   	dp[v] = s[v - 1] - '0';
   	int rb = 0, rc = 0;
   	for(int i = 0; i < V[v].size(); i++) {
   		int u = V[v][i];
   		if(!vis[u]) {
   			dfs(u, root);
   			rb += dp[u];
   			rc = max(rc, dp[u]);
   		}
   	}
   	if(v == root)
   		dp[v] = rc + 1;
   	else {
   		rb -= s[v-1] - '0';
   		dp[v] = max(dp[v], rb);
   	}
}
    
int main() {
 	int n;
   	cin>>n;
   	for(int i=0; i<(n-1); i++) {
   		int a, b;
   		cin>>a>>b;
   		V[a].push_back(b);
   		V[b].push_back(a);
   	}
   	cin>>s;
   	int ans = 0;
   	for(int i=1; i<=n; i++) {
  		if(s[i-1] == '1') {
   			clear(n);
   			dfs(i, i);
   			ans = max(ans, dp[i]);
   		}
   	}
 	cout<<ans;
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < V[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
power.cpp: In function 'int main()':
power.cpp:41:7: error: 'clear' was not declared in this scope
   41 |       clear(n);
      |       ^~~~~