Submission #391360

# Submission time Handle Problem Language Result Execution time Memory
391360 2021-04-18T16:07:07 Z lukameladze Power Plant (JOI20_power) C++14
100 / 100
268 ms 30864 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+5;
long long par[N],dp[N],dp1[N],n,a,b,bb,ans;
vector <long long> v[N];
string s;
void dfs (int a, int p) {
     int ff=0;
     for (int i=0; i<v[a].size(); i++) {
          if (v[a][i]!=p) {
               dfs(v[a][i],a);
               dp[a]+=dp[v[a][i]];
               if (s[a]=='1' && !ff) dp[a]--, ff=1;
               dp1[a]+=dp1[v[a][i]];
          }
     }
  if (s[a]=='1')
     dp1[a]++;
    if (s[a]=='1') dp[a]=max(1LL, dp[a]);
    if (s[a]=='0') dp[a]=max(0LL,dp[a]);
}
int main() {
     cin>>n;
     for (int i=1; i<=n-1; i++) {
          cin>>a>>b;
          v[a].pb(b);
          v[b].pb(a);
     }
     cin>>s;
     s="@"+s;
     dfs(1,0);
     for (int i=1; i<=n; i++) {
          if (dp1[1]-dp1[i]>0) bb=1; else bb=0;
          ans=max(ans,dp[i]+bb);
     }
     cout<<ans<<endl;
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |      for (int i=0; i<v[a].size(); i++) {
      |                    ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 5 ms 7272 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7244 KB Output is correct
15 Correct 5 ms 7244 KB Output is correct
16 Correct 5 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 5 ms 7356 KB Output is correct
19 Correct 5 ms 7244 KB Output is correct
20 Correct 5 ms 7244 KB Output is correct
21 Correct 5 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 5 ms 7272 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7244 KB Output is correct
15 Correct 5 ms 7244 KB Output is correct
16 Correct 5 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 5 ms 7356 KB Output is correct
19 Correct 5 ms 7244 KB Output is correct
20 Correct 5 ms 7244 KB Output is correct
21 Correct 5 ms 7244 KB Output is correct
22 Correct 6 ms 7372 KB Output is correct
23 Correct 6 ms 7372 KB Output is correct
24 Correct 7 ms 7372 KB Output is correct
25 Correct 6 ms 7372 KB Output is correct
26 Correct 6 ms 7372 KB Output is correct
27 Correct 6 ms 7372 KB Output is correct
28 Correct 6 ms 7372 KB Output is correct
29 Correct 6 ms 7536 KB Output is correct
30 Correct 6 ms 7500 KB Output is correct
31 Correct 6 ms 7500 KB Output is correct
32 Correct 6 ms 7408 KB Output is correct
33 Correct 6 ms 7428 KB Output is correct
34 Correct 6 ms 7372 KB Output is correct
35 Correct 6 ms 7372 KB Output is correct
36 Correct 6 ms 7372 KB Output is correct
37 Correct 6 ms 7372 KB Output is correct
38 Correct 6 ms 7376 KB Output is correct
39 Correct 8 ms 7500 KB Output is correct
40 Correct 6 ms 7504 KB Output is correct
41 Correct 6 ms 7500 KB Output is correct
42 Correct 6 ms 7500 KB Output is correct
43 Correct 6 ms 7372 KB Output is correct
44 Correct 6 ms 7452 KB Output is correct
45 Correct 6 ms 7372 KB Output is correct
46 Correct 6 ms 7372 KB Output is correct
47 Correct 6 ms 7372 KB Output is correct
48 Correct 6 ms 7444 KB Output is correct
49 Correct 6 ms 7500 KB Output is correct
50 Correct 6 ms 7500 KB Output is correct
51 Correct 6 ms 7500 KB Output is correct
52 Correct 6 ms 7372 KB Output is correct
53 Correct 6 ms 7500 KB Output is correct
54 Correct 6 ms 7372 KB Output is correct
55 Correct 6 ms 7372 KB Output is correct
56 Correct 6 ms 7372 KB Output is correct
57 Correct 6 ms 7500 KB Output is correct
58 Correct 6 ms 7428 KB Output is correct
59 Correct 6 ms 7372 KB Output is correct
60 Correct 6 ms 7500 KB Output is correct
61 Correct 6 ms 7372 KB Output is correct
62 Correct 6 ms 7500 KB Output is correct
63 Correct 6 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7244 KB Output is correct
8 Correct 5 ms 7244 KB Output is correct
9 Correct 5 ms 7244 KB Output is correct
10 Correct 5 ms 7244 KB Output is correct
11 Correct 5 ms 7244 KB Output is correct
12 Correct 5 ms 7272 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7244 KB Output is correct
15 Correct 5 ms 7244 KB Output is correct
16 Correct 5 ms 7244 KB Output is correct
17 Correct 5 ms 7244 KB Output is correct
18 Correct 5 ms 7356 KB Output is correct
19 Correct 5 ms 7244 KB Output is correct
20 Correct 5 ms 7244 KB Output is correct
21 Correct 5 ms 7244 KB Output is correct
22 Correct 6 ms 7372 KB Output is correct
23 Correct 6 ms 7372 KB Output is correct
24 Correct 7 ms 7372 KB Output is correct
25 Correct 6 ms 7372 KB Output is correct
26 Correct 6 ms 7372 KB Output is correct
27 Correct 6 ms 7372 KB Output is correct
28 Correct 6 ms 7372 KB Output is correct
29 Correct 6 ms 7536 KB Output is correct
30 Correct 6 ms 7500 KB Output is correct
31 Correct 6 ms 7500 KB Output is correct
32 Correct 6 ms 7408 KB Output is correct
33 Correct 6 ms 7428 KB Output is correct
34 Correct 6 ms 7372 KB Output is correct
35 Correct 6 ms 7372 KB Output is correct
36 Correct 6 ms 7372 KB Output is correct
37 Correct 6 ms 7372 KB Output is correct
38 Correct 6 ms 7376 KB Output is correct
39 Correct 8 ms 7500 KB Output is correct
40 Correct 6 ms 7504 KB Output is correct
41 Correct 6 ms 7500 KB Output is correct
42 Correct 6 ms 7500 KB Output is correct
43 Correct 6 ms 7372 KB Output is correct
44 Correct 6 ms 7452 KB Output is correct
45 Correct 6 ms 7372 KB Output is correct
46 Correct 6 ms 7372 KB Output is correct
47 Correct 6 ms 7372 KB Output is correct
48 Correct 6 ms 7444 KB Output is correct
49 Correct 6 ms 7500 KB Output is correct
50 Correct 6 ms 7500 KB Output is correct
51 Correct 6 ms 7500 KB Output is correct
52 Correct 6 ms 7372 KB Output is correct
53 Correct 6 ms 7500 KB Output is correct
54 Correct 6 ms 7372 KB Output is correct
55 Correct 6 ms 7372 KB Output is correct
56 Correct 6 ms 7372 KB Output is correct
57 Correct 6 ms 7500 KB Output is correct
58 Correct 6 ms 7428 KB Output is correct
59 Correct 6 ms 7372 KB Output is correct
60 Correct 6 ms 7500 KB Output is correct
61 Correct 6 ms 7372 KB Output is correct
62 Correct 6 ms 7500 KB Output is correct
63 Correct 6 ms 7372 KB Output is correct
64 Correct 253 ms 18068 KB Output is correct
65 Correct 246 ms 18056 KB Output is correct
66 Correct 243 ms 18152 KB Output is correct
67 Correct 239 ms 18148 KB Output is correct
68 Correct 244 ms 18064 KB Output is correct
69 Correct 253 ms 18300 KB Output is correct
70 Correct 250 ms 18064 KB Output is correct
71 Correct 242 ms 18072 KB Output is correct
72 Correct 247 ms 18132 KB Output is correct
73 Correct 267 ms 29712 KB Output is correct
74 Correct 261 ms 29616 KB Output is correct
75 Correct 244 ms 19328 KB Output is correct
76 Correct 245 ms 19348 KB Output is correct
77 Correct 253 ms 18188 KB Output is correct
78 Correct 256 ms 18168 KB Output is correct
79 Correct 248 ms 18064 KB Output is correct
80 Correct 256 ms 18080 KB Output is correct
81 Correct 216 ms 18208 KB Output is correct
82 Correct 243 ms 18108 KB Output is correct
83 Correct 268 ms 23252 KB Output is correct
84 Correct 258 ms 25364 KB Output is correct
85 Correct 259 ms 25028 KB Output is correct
86 Correct 247 ms 19396 KB Output is correct
87 Correct 247 ms 18864 KB Output is correct
88 Correct 237 ms 19000 KB Output is correct
89 Correct 243 ms 19048 KB Output is correct
90 Correct 239 ms 18832 KB Output is correct
91 Correct 244 ms 19056 KB Output is correct
92 Correct 254 ms 19344 KB Output is correct
93 Correct 244 ms 21736 KB Output is correct
94 Correct 240 ms 23352 KB Output is correct
95 Correct 228 ms 22052 KB Output is correct
96 Correct 238 ms 20144 KB Output is correct
97 Correct 232 ms 18780 KB Output is correct
98 Correct 232 ms 18224 KB Output is correct
99 Correct 238 ms 18144 KB Output is correct
100 Correct 242 ms 21112 KB Output is correct
101 Correct 241 ms 18976 KB Output is correct
102 Correct 235 ms 18552 KB Output is correct
103 Correct 245 ms 18504 KB Output is correct
104 Correct 180 ms 17200 KB Output is correct
105 Correct 261 ms 26524 KB Output is correct
106 Correct 182 ms 18704 KB Output is correct
107 Correct 177 ms 18736 KB Output is correct
108 Correct 259 ms 30520 KB Output is correct
109 Correct 187 ms 17208 KB Output is correct
110 Correct 255 ms 30864 KB Output is correct
111 Correct 237 ms 18052 KB Output is correct