# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
788017 | YassineBenYounes | Power Plant (JOI20_power) | C++17 | 196 ms | 30300 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define vii vector<pii>
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const int mx = 3e5+5;
const ll mod = 1e9+7;
vector<int> graph[mx];
string s;
int dp_down[mx];
int ans = 0;
void dfs(int node, int p){
int l = 0, sum = 0;
for(int adj : graph[node]){
if(adj == p)continue;
dfs(adj ,node);
sum += dp_down[adj];
l = max(l, dp_down[adj]);
}
int k = (s[node] == '1');
sum -= k;
dp_down[node] = max(dp_down[node], k);
dp_down[node] = max(dp_down[node], sum);
ans = max(ans, l+k);
ans = max(ans, dp_down[node]);
}
void runcase(){
int n;cin >> n;
for(int i = 0; i < n-1;i++){
int a, b;cin >> a >> b;
graph[a].pb(b);
graph[b].pb(a);
}
cin >> s;
s = "Y" + s;
dfs(1, 1);
cout << ans << endl;
}
int main(){
int t;
//cin >> t;
t = 1;
while(t--){
runcase();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |