Submission #889483

# Submission time Handle Problem Language Result Execution time Memory
889483 2023-12-19T19:55:12 Z Mr_Ph Power Plant (JOI20_power) C++17
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<x, null_type,
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
vector<vector<int>>adj;
string s;
int n;
int dp[200001];
int ans1=0;
int ans(int node,int p)
{
    //cout<<node<<" "<<p<<endl;
    int e=0,e1=0;
    for(auto i:adj[node])
    {//
        //cout<<i<<endl;
        if(i==p)continue;
        int x=ans(i,node);
        e1+=x;
    }
    if(s[node-1]=='1')e1=max(e1-1,1ll);
    return dp[node]=e1;
}
void preprocess() {}
void solve()
{
    cin>>n;
    adj.resize(n+1);
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin>>s;
    ans(1,0);
    int x=0;
    for(int i=1;i<=n;i++)
    if(s[i-1]=='1')x=max(x,dp[i]+1);
    cout<<x<<endl;
}
signed main()
{
  //   freopen("meta_game_input.txt","r",stdin);
//     freopen("otput.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    preprocess();
    int t=1,st;
    //cin>>t;
    while(t--)
        solve();
}

Compilation message

power.cpp: In function 'long long int ans(long long int, long long int)':
power.cpp:26:9: warning: unused variable 'e' [-Wunused-variable]
   26 |     int e=0,e1=0;
      |         ^
power.cpp: In function 'int main()':
power.cpp:63:13: warning: unused variable 'st' [-Wunused-variable]
   63 |     int t=1,st;
      |             ^~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -