답안 #849974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849974 2023-09-15T15:12:42 Z Mr_Ph Power Plant (JOI20_power) C++14
100 / 100
127 ms 24208 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;
    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()
{
    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:31:9: warning: unused variable 'e' [-Wunused-variable]
   31 |     int e=0,e1=0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 856 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 600 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 600 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 856 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 1 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 600 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 600 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 93 ms 14228 KB Output is correct
65 Correct 71 ms 14252 KB Output is correct
66 Correct 94 ms 14208 KB Output is correct
67 Correct 65 ms 14220 KB Output is correct
68 Correct 73 ms 14208 KB Output is correct
69 Correct 59 ms 14372 KB Output is correct
70 Correct 64 ms 14240 KB Output is correct
71 Correct 85 ms 14504 KB Output is correct
72 Correct 64 ms 14220 KB Output is correct
73 Correct 101 ms 23372 KB Output is correct
74 Correct 100 ms 23280 KB Output is correct
75 Correct 78 ms 15604 KB Output is correct
76 Correct 73 ms 15424 KB Output is correct
77 Correct 101 ms 14216 KB Output is correct
78 Correct 100 ms 14220 KB Output is correct
79 Correct 84 ms 14136 KB Output is correct
80 Correct 82 ms 14288 KB Output is correct
81 Correct 78 ms 14448 KB Output is correct
82 Correct 60 ms 14280 KB Output is correct
83 Correct 73 ms 18208 KB Output is correct
84 Correct 107 ms 20048 KB Output is correct
85 Correct 78 ms 19868 KB Output is correct
86 Correct 87 ms 15780 KB Output is correct
87 Correct 124 ms 14988 KB Output is correct
88 Correct 68 ms 15052 KB Output is correct
89 Correct 69 ms 15096 KB Output is correct
90 Correct 64 ms 14840 KB Output is correct
91 Correct 77 ms 15068 KB Output is correct
92 Correct 64 ms 15520 KB Output is correct
93 Correct 72 ms 17216 KB Output is correct
94 Correct 81 ms 18372 KB Output is correct
95 Correct 69 ms 17348 KB Output is correct
96 Correct 69 ms 15792 KB Output is correct
97 Correct 65 ms 14824 KB Output is correct
98 Correct 68 ms 14556 KB Output is correct
99 Correct 69 ms 14364 KB Output is correct
100 Correct 65 ms 16764 KB Output is correct
101 Correct 87 ms 14988 KB Output is correct
102 Correct 84 ms 14456 KB Output is correct
103 Correct 66 ms 14512 KB Output is correct
104 Correct 43 ms 14792 KB Output is correct
105 Correct 80 ms 20720 KB Output is correct
106 Correct 59 ms 14824 KB Output is correct
107 Correct 54 ms 15028 KB Output is correct
108 Correct 79 ms 23952 KB Output is correct
109 Correct 40 ms 14864 KB Output is correct
110 Correct 127 ms 24208 KB Output is correct
111 Correct 69 ms 14164 KB Output is correct