답안 #889486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889486 2023-12-19T19:58:16 Z Mr_Ph Power Plant (JOI20_power) C++17
100 / 100
96 ms 29584 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 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')
            ans1=max(ans1,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;
    cout<<max(ans(1,-1),ans1)<<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:32:9: warning: unused variable 'e' [-Wunused-variable]
   32 |     int e=0,e1=0;
      |         ^
# 결과 실행 시간 메모리 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 1884 KB Output is correct
7 Correct 1 ms 1884 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 1884 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
# 결과 실행 시간 메모리 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 1884 KB Output is correct
7 Correct 1 ms 1884 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 1884 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 1 ms 2140 KB Output is correct
23 Correct 1 ms 2140 KB Output is correct
24 Correct 1 ms 2140 KB Output is correct
25 Correct 1 ms 2140 KB Output is correct
26 Correct 1 ms 2136 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 1 ms 2040 KB Output is correct
32 Correct 1 ms 2140 KB Output is correct
33 Correct 1 ms 2140 KB Output is correct
34 Correct 1 ms 2140 KB Output is correct
35 Correct 1 ms 2140 KB Output is correct
36 Correct 1 ms 2136 KB Output is correct
37 Correct 2 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 2140 KB Output is correct
41 Correct 1 ms 2140 KB Output is correct
42 Correct 1 ms 2140 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 2164 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 2172 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 2004 KB Output is correct
57 Correct 1 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 2 ms 2140 KB Output is correct
62 Correct 1 ms 2040 KB Output is correct
63 Correct 1 ms 2144 KB Output is correct
# 결과 실행 시간 메모리 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 1884 KB Output is correct
7 Correct 1 ms 1884 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 1884 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 1 ms 2140 KB Output is correct
23 Correct 1 ms 2140 KB Output is correct
24 Correct 1 ms 2140 KB Output is correct
25 Correct 1 ms 2140 KB Output is correct
26 Correct 1 ms 2136 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 1 ms 2040 KB Output is correct
32 Correct 1 ms 2140 KB Output is correct
33 Correct 1 ms 2140 KB Output is correct
34 Correct 1 ms 2140 KB Output is correct
35 Correct 1 ms 2140 KB Output is correct
36 Correct 1 ms 2136 KB Output is correct
37 Correct 2 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 2140 KB Output is correct
41 Correct 1 ms 2140 KB Output is correct
42 Correct 1 ms 2140 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 2164 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 2172 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 2004 KB Output is correct
57 Correct 1 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 2 ms 2140 KB Output is correct
62 Correct 1 ms 2040 KB Output is correct
63 Correct 1 ms 2144 KB Output is correct
64 Correct 63 ms 17208 KB Output is correct
65 Correct 68 ms 17212 KB Output is correct
66 Correct 71 ms 17196 KB Output is correct
67 Correct 70 ms 17036 KB Output is correct
68 Correct 62 ms 17232 KB Output is correct
69 Correct 80 ms 17176 KB Output is correct
70 Correct 59 ms 17056 KB Output is correct
71 Correct 89 ms 17056 KB Output is correct
72 Correct 65 ms 17200 KB Output is correct
73 Correct 81 ms 28564 KB Output is correct
74 Correct 96 ms 28672 KB Output is correct
75 Correct 66 ms 18452 KB Output is correct
76 Correct 67 ms 18232 KB Output is correct
77 Correct 67 ms 17036 KB Output is correct
78 Correct 64 ms 17208 KB Output is correct
79 Correct 63 ms 17212 KB Output is correct
80 Correct 65 ms 17056 KB Output is correct
81 Correct 56 ms 17100 KB Output is correct
82 Correct 65 ms 16928 KB Output is correct
83 Correct 76 ms 21968 KB Output is correct
84 Correct 77 ms 24084 KB Output is correct
85 Correct 79 ms 23976 KB Output is correct
86 Correct 65 ms 18384 KB Output is correct
87 Correct 67 ms 17808 KB Output is correct
88 Correct 72 ms 17748 KB Output is correct
89 Correct 66 ms 17820 KB Output is correct
90 Correct 63 ms 17656 KB Output is correct
91 Correct 64 ms 17948 KB Output is correct
92 Correct 65 ms 18308 KB Output is correct
93 Correct 63 ms 20428 KB Output is correct
94 Correct 66 ms 22092 KB Output is correct
95 Correct 63 ms 20928 KB Output is correct
96 Correct 62 ms 18956 KB Output is correct
97 Correct 59 ms 17500 KB Output is correct
98 Correct 58 ms 17204 KB Output is correct
99 Correct 61 ms 17208 KB Output is correct
100 Correct 79 ms 20092 KB Output is correct
101 Correct 63 ms 17996 KB Output is correct
102 Correct 57 ms 17248 KB Output is correct
103 Correct 62 ms 17332 KB Output is correct
104 Correct 46 ms 17768 KB Output is correct
105 Correct 80 ms 25488 KB Output is correct
106 Correct 43 ms 17612 KB Output is correct
107 Correct 43 ms 17600 KB Output is correct
108 Correct 86 ms 29328 KB Output is correct
109 Correct 43 ms 17604 KB Output is correct
110 Correct 79 ms 29584 KB Output is correct
111 Correct 59 ms 16960 KB Output is correct