Submission #735776

# Submission time Handle Problem Language Result Execution time Memory
735776 2023-05-04T16:06:16 Z alexdd Power Plant (JOI20_power) C++17
0 / 100
3 ms 5036 KB
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n;
vector<int> con[200005];
int dp[200005][2];
bool iss[200005];
int mxm=0;
void dfs(int nod, int par)
{
    dp[nod][0]=0;
    dp[nod][1]=0;
    int sum0=0, max1=0, max0=0;
    for(auto adj:con[nod])
    {
        if(adj!=par)
        {
            dfs(adj,nod);
            sum0 += dp[adj][0];
            max1 = max(max1, dp[adj][1]);
            max0 = max(max0, dp[adj][0]);
        }
    }
    if(iss[nod])
    {
        dp[nod][0] = max(1, sum0-1);
        dp[nod][1] = max0 + 1;///dp[nod][1] = max(dp[adj][0]) + 1
    }
    else
    {
        dp[nod][0] = sum0;
        dp[nod][1] = max1;///dp[nod][1] = max(dp[adj][1])
    }
    //cout<<nod<<"  "<<dp[nod][0]<<" "<<dp[nod][1]<<"    "<<iss[nod]<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        con[a].push_back(b);
        con[b].push_back(a);
    }
    int cnt1=0;
    char ch;
    for(int i=1;i<=n;i++)
    {
        cin>>ch;
        if(ch=='1')
            iss[i]=1;
        else
            iss[i]=0;
        if(iss[i])
            cnt1++;
    }
    dfs(1,0);
    cout<<max(dp[1][0], dp[1][1]);
    return 0;
}
/**

dp[nod][0] = scorul maxim pe care il putem obtine daca nu avem niciun nod "in-danger"
dp[nod][1] = scorul maxim pe care il putem obtine daca avem un nod "in-danger"


*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Incorrect 3 ms 4948 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Incorrect 3 ms 4948 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5036 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Incorrect 3 ms 4948 KB Output isn't correct
8 Halted 0 ms 0 KB -