Submission #889492

# Submission time Handle Problem Language Result Execution time Memory
889492 2023-12-19T20:20:26 Z Mr_Ph Power Plant (JOI20_power) C++17
0 / 100
1 ms 1880 KB
///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
//#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#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 xd=0;
void 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;
        ans(i,node);
        int x=dp[i];
        if(s[node-1]=='1')xd=max(xd,x+1);
        e1+=x;
    }
    if(s[node-1]=='1'&&adj[node].sz>=2)e1=max(e1-1,1ll);
     dp[node]=e1;
}
void preprocess() {}
void solve()
{
    memset(dp,-1,sizeof dp);
    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);
    cout<<xd<<endl;
}
signed main()
{
    // freopen("div7.in","r",stdin);
    //freopen("div7.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    preprocess();
    //bla();
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}

Compilation message

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