Submission #889491

# Submission time Handle Problem Language Result Execution time Memory
889491 2023-12-19T20:09:33 Z Mr_Ph Power Plant (JOI20_power) C++17
100 / 100
112 ms 27028 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;
int ans(int node,int p)
{
    //cout<<node<<" "<<p<<endl;
    if(dp[node]!=-1)return dp[node];
    int e=0,e1=0;
    for(auto i:adj[node])
    {//
        //cout<<i<<endl;
        if(i==p)continue;
        int x=ans(i,node);
        if(s[node-1]=='1')xd=max(xd,x+1);
        e1+=x;
    }
    if(s[node-1]=='1')e1=max(e1-1,1ll);
    return 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;
    xd=max(xd,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 'long long int ans(long long int, long long int)':
power.cpp:33:9: warning: unused variable 'e' [-Wunused-variable]
   33 |     int e=0,e1=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1880 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1880 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1880 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1880 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
22 Correct 2 ms 2140 KB Output is correct
23 Correct 1 ms 2140 KB Output is correct
24 Correct 2 ms 2140 KB Output is correct
25 Correct 1 ms 2140 KB Output is correct
26 Correct 1 ms 2140 KB Output is correct
27 Correct 1 ms 2140 KB Output is correct
28 Correct 1 ms 2140 KB Output is correct
29 Correct 1 ms 2140 KB Output is correct
30 Correct 1 ms 2140 KB Output is correct
31 Correct 2 ms 2140 KB Output is correct
32 Correct 1 ms 2140 KB Output is correct
33 Correct 1 ms 2140 KB Output is correct
34 Correct 2 ms 2140 KB Output is correct
35 Correct 1 ms 2140 KB Output is correct
36 Correct 1 ms 2140 KB Output is correct
37 Correct 1 ms 2140 KB Output is correct
38 Correct 2 ms 2140 KB Output is correct
39 Correct 1 ms 2140 KB Output is correct
40 Correct 1 ms 2388 KB Output is correct
41 Correct 1 ms 2336 KB Output is correct
42 Correct 2 ms 2136 KB Output is correct
43 Correct 1 ms 2140 KB Output is correct
44 Correct 1 ms 2140 KB Output is correct
45 Correct 1 ms 2140 KB Output is correct
46 Correct 1 ms 2140 KB Output is correct
47 Correct 1 ms 2140 KB Output is correct
48 Correct 1 ms 2140 KB Output is correct
49 Correct 1 ms 2140 KB Output is correct
50 Correct 1 ms 2140 KB Output is correct
51 Correct 1 ms 2140 KB Output is correct
52 Correct 1 ms 2140 KB Output is correct
53 Correct 1 ms 2140 KB Output is correct
54 Correct 1 ms 2140 KB Output is correct
55 Correct 1 ms 2140 KB Output is correct
56 Correct 1 ms 2140 KB Output is correct
57 Correct 2 ms 2140 KB Output is correct
58 Correct 1 ms 2140 KB Output is correct
59 Correct 1 ms 2140 KB Output is correct
60 Correct 1 ms 2140 KB Output is correct
61 Correct 1 ms 2140 KB Output is correct
62 Correct 1 ms 2140 KB Output is correct
63 Correct 1 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1880 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1880 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 1 ms 1884 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
22 Correct 2 ms 2140 KB Output is correct
23 Correct 1 ms 2140 KB Output is correct
24 Correct 2 ms 2140 KB Output is correct
25 Correct 1 ms 2140 KB Output is correct
26 Correct 1 ms 2140 KB Output is correct
27 Correct 1 ms 2140 KB Output is correct
28 Correct 1 ms 2140 KB Output is correct
29 Correct 1 ms 2140 KB Output is correct
30 Correct 1 ms 2140 KB Output is correct
31 Correct 2 ms 2140 KB Output is correct
32 Correct 1 ms 2140 KB Output is correct
33 Correct 1 ms 2140 KB Output is correct
34 Correct 2 ms 2140 KB Output is correct
35 Correct 1 ms 2140 KB Output is correct
36 Correct 1 ms 2140 KB Output is correct
37 Correct 1 ms 2140 KB Output is correct
38 Correct 2 ms 2140 KB Output is correct
39 Correct 1 ms 2140 KB Output is correct
40 Correct 1 ms 2388 KB Output is correct
41 Correct 1 ms 2336 KB Output is correct
42 Correct 2 ms 2136 KB Output is correct
43 Correct 1 ms 2140 KB Output is correct
44 Correct 1 ms 2140 KB Output is correct
45 Correct 1 ms 2140 KB Output is correct
46 Correct 1 ms 2140 KB Output is correct
47 Correct 1 ms 2140 KB Output is correct
48 Correct 1 ms 2140 KB Output is correct
49 Correct 1 ms 2140 KB Output is correct
50 Correct 1 ms 2140 KB Output is correct
51 Correct 1 ms 2140 KB Output is correct
52 Correct 1 ms 2140 KB Output is correct
53 Correct 1 ms 2140 KB Output is correct
54 Correct 1 ms 2140 KB Output is correct
55 Correct 1 ms 2140 KB Output is correct
56 Correct 1 ms 2140 KB Output is correct
57 Correct 2 ms 2140 KB Output is correct
58 Correct 1 ms 2140 KB Output is correct
59 Correct 1 ms 2140 KB Output is correct
60 Correct 1 ms 2140 KB Output is correct
61 Correct 1 ms 2140 KB Output is correct
62 Correct 1 ms 2140 KB Output is correct
63 Correct 1 ms 2140 KB Output is correct
64 Correct 73 ms 14396 KB Output is correct
65 Correct 70 ms 14360 KB Output is correct
66 Correct 64 ms 14388 KB Output is correct
67 Correct 62 ms 14388 KB Output is correct
68 Correct 79 ms 14400 KB Output is correct
69 Correct 96 ms 14388 KB Output is correct
70 Correct 65 ms 14400 KB Output is correct
71 Correct 65 ms 14368 KB Output is correct
72 Correct 63 ms 14388 KB Output is correct
73 Correct 78 ms 26008 KB Output is correct
74 Correct 86 ms 25744 KB Output is correct
75 Correct 74 ms 15664 KB Output is correct
76 Correct 65 ms 15604 KB Output is correct
77 Correct 97 ms 14400 KB Output is correct
78 Correct 90 ms 14356 KB Output is correct
79 Correct 60 ms 14400 KB Output is correct
80 Correct 61 ms 14384 KB Output is correct
81 Correct 58 ms 14276 KB Output is correct
82 Correct 59 ms 14280 KB Output is correct
83 Correct 95 ms 19408 KB Output is correct
84 Correct 70 ms 21404 KB Output is correct
85 Correct 112 ms 21152 KB Output is correct
86 Correct 70 ms 15764 KB Output is correct
87 Correct 81 ms 14996 KB Output is correct
88 Correct 65 ms 15260 KB Output is correct
89 Correct 62 ms 15260 KB Output is correct
90 Correct 62 ms 14836 KB Output is correct
91 Correct 79 ms 15212 KB Output is correct
92 Correct 64 ms 15492 KB Output is correct
93 Correct 75 ms 17916 KB Output is correct
94 Correct 65 ms 19400 KB Output is correct
95 Correct 91 ms 18220 KB Output is correct
96 Correct 82 ms 16496 KB Output is correct
97 Correct 60 ms 14864 KB Output is correct
98 Correct 55 ms 14532 KB Output is correct
99 Correct 75 ms 14432 KB Output is correct
100 Correct 60 ms 17284 KB Output is correct
101 Correct 83 ms 15268 KB Output is correct
102 Correct 59 ms 14432 KB Output is correct
103 Correct 62 ms 14688 KB Output is correct
104 Correct 45 ms 14796 KB Output is correct
105 Correct 83 ms 22676 KB Output is correct
106 Correct 54 ms 14932 KB Output is correct
107 Correct 43 ms 14784 KB Output is correct
108 Correct 78 ms 26568 KB Output is correct
109 Correct 54 ms 14900 KB Output is correct
110 Correct 79 ms 27028 KB Output is correct
111 Correct 82 ms 14332 KB Output is correct