답안 #889494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889494 2023-12-19T20:24:49 Z Mr_Ph Power Plant (JOI20_power) C++17
100 / 100
94 ms 27092 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')e1=max(e1-1,1ll);
    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;
    ans(1,0);
    xd=max(xd,dp[1]);
    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;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 604 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 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 856 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 1 ms 548 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 396 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 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 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 604 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 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 856 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 1 ms 548 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 396 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 79 ms 14380 KB Output is correct
65 Correct 63 ms 14224 KB Output is correct
66 Correct 67 ms 14392 KB Output is correct
67 Correct 60 ms 14224 KB Output is correct
68 Correct 67 ms 14208 KB Output is correct
69 Correct 72 ms 14256 KB Output is correct
70 Correct 84 ms 14248 KB Output is correct
71 Correct 73 ms 14384 KB Output is correct
72 Correct 65 ms 14356 KB Output is correct
73 Correct 78 ms 26256 KB Output is correct
74 Correct 81 ms 26056 KB Output is correct
75 Correct 65 ms 15508 KB Output is correct
76 Correct 70 ms 15508 KB Output is correct
77 Correct 69 ms 14360 KB Output is correct
78 Correct 66 ms 14252 KB Output is correct
79 Correct 67 ms 14232 KB Output is correct
80 Correct 66 ms 14224 KB Output is correct
81 Correct 67 ms 14544 KB Output is correct
82 Correct 72 ms 14280 KB Output is correct
83 Correct 80 ms 19476 KB Output is correct
84 Correct 76 ms 21464 KB Output is correct
85 Correct 81 ms 21296 KB Output is correct
86 Correct 68 ms 15504 KB Output is correct
87 Correct 84 ms 15240 KB Output is correct
88 Correct 78 ms 15060 KB Output is correct
89 Correct 65 ms 15412 KB Output is correct
90 Correct 66 ms 14836 KB Output is correct
91 Correct 68 ms 15224 KB Output is correct
92 Correct 71 ms 15484 KB Output is correct
93 Correct 72 ms 17808 KB Output is correct
94 Correct 66 ms 19400 KB Output is correct
95 Correct 62 ms 18116 KB Output is correct
96 Correct 66 ms 16228 KB Output is correct
97 Correct 73 ms 14840 KB Output is correct
98 Correct 60 ms 14544 KB Output is correct
99 Correct 66 ms 14228 KB Output is correct
100 Correct 62 ms 17276 KB Output is correct
101 Correct 81 ms 15228 KB Output is correct
102 Correct 62 ms 14436 KB Output is correct
103 Correct 59 ms 14512 KB Output is correct
104 Correct 42 ms 14788 KB Output is correct
105 Correct 94 ms 22676 KB Output is correct
106 Correct 42 ms 15052 KB Output is correct
107 Correct 46 ms 14928 KB Output is correct
108 Correct 83 ms 26684 KB Output is correct
109 Correct 47 ms 14784 KB Output is correct
110 Correct 79 ms 27092 KB Output is correct
111 Correct 58 ms 14320 KB Output is correct