Submission #516483

# Submission time Handle Problem Language Result Execution time Memory
516483 2022-01-21T11:59:13 Z leinad2 Power Plant (JOI20_power) C++17
100 / 100
171 ms 29644 KB
#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, a, b, A[200010], dp[200010], ans;
vector<int>adj[200010];
char S[200010];
void dfs(int v, int par)
{
    int a=0, b=0;
    for(auto p:adj[v])
    {
        if(p==par)continue;
        dfs(p, v);
        a+=dp[p];
        b=max(b, dp[p]);
    }
    dp[v]=max(a-A[v], A[v]);
    ans=max(ans, b+A[v]);
    ans=max(ans, dp[v]);
}
main()
{
    scanf("%d", &n);
    for(i=0;++i<n;)
    {
        scanf("%d %d", &a, &b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    scanf("%s", &S);
    for(i=0;i++<n;)A[i]=S[i-1]-'0';
    dfs(1, 0);
    cout<<ans;
}

Compilation message

power.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main()
      | ^~~~
power.cpp: In function 'int main()':
power.cpp:29:13: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[200010]' [-Wformat=]
   29 |     scanf("%s", &S);
      |            ~^   ~~
      |             |   |
      |             |   char (*)[200010]
      |             char*
power.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
power.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
power.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%s", &S);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 5008 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 5012 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 2 ms 5000 KB Output is correct
11 Correct 3 ms 5000 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 4 ms 5008 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 5008 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 5012 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 2 ms 5000 KB Output is correct
11 Correct 3 ms 5000 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 4 ms 5008 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5020 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 5 ms 5196 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5144 KB Output is correct
30 Correct 3 ms 5196 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5112 KB Output is correct
35 Correct 4 ms 5024 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5144 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 3 ms 5020 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 3 ms 5148 KB Output is correct
45 Correct 4 ms 5020 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 4 ms 5016 KB Output is correct
48 Correct 4 ms 5148 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 4 ms 5124 KB Output is correct
51 Correct 5 ms 5068 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 4 ms 5124 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 3 ms 5016 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 3 ms 5012 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5148 KB Output is correct
61 Correct 3 ms 5068 KB Output is correct
62 Correct 3 ms 5148 KB Output is correct
63 Correct 3 ms 5020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 5008 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 5012 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 2 ms 5000 KB Output is correct
11 Correct 3 ms 5000 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 2 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 5008 KB Output is correct
19 Correct 4 ms 5008 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 5068 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5020 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 5 ms 5196 KB Output is correct
28 Correct 3 ms 5068 KB Output is correct
29 Correct 3 ms 5144 KB Output is correct
30 Correct 3 ms 5196 KB Output is correct
31 Correct 4 ms 5068 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 4 ms 5068 KB Output is correct
34 Correct 4 ms 5112 KB Output is correct
35 Correct 4 ms 5024 KB Output is correct
36 Correct 3 ms 5068 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 3 ms 5068 KB Output is correct
39 Correct 3 ms 5144 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 3 ms 5020 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 3 ms 5148 KB Output is correct
45 Correct 4 ms 5020 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 4 ms 5016 KB Output is correct
48 Correct 4 ms 5148 KB Output is correct
49 Correct 3 ms 5068 KB Output is correct
50 Correct 4 ms 5124 KB Output is correct
51 Correct 5 ms 5068 KB Output is correct
52 Correct 4 ms 5068 KB Output is correct
53 Correct 4 ms 5124 KB Output is correct
54 Correct 4 ms 5068 KB Output is correct
55 Correct 3 ms 5016 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 3 ms 5196 KB Output is correct
58 Correct 3 ms 5012 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5148 KB Output is correct
61 Correct 3 ms 5068 KB Output is correct
62 Correct 3 ms 5148 KB Output is correct
63 Correct 3 ms 5020 KB Output is correct
64 Correct 155 ms 15892 KB Output is correct
65 Correct 131 ms 15812 KB Output is correct
66 Correct 126 ms 15824 KB Output is correct
67 Correct 129 ms 15768 KB Output is correct
68 Correct 128 ms 15776 KB Output is correct
69 Correct 132 ms 15736 KB Output is correct
70 Correct 136 ms 15800 KB Output is correct
71 Correct 132 ms 15924 KB Output is correct
72 Correct 147 ms 15948 KB Output is correct
73 Correct 171 ms 28428 KB Output is correct
74 Correct 145 ms 28360 KB Output is correct
75 Correct 124 ms 15704 KB Output is correct
76 Correct 135 ms 15652 KB Output is correct
77 Correct 125 ms 15636 KB Output is correct
78 Correct 122 ms 15616 KB Output is correct
79 Correct 146 ms 15624 KB Output is correct
80 Correct 124 ms 15668 KB Output is correct
81 Correct 115 ms 16036 KB Output is correct
82 Correct 118 ms 15808 KB Output is correct
83 Correct 161 ms 20996 KB Output is correct
84 Correct 149 ms 23048 KB Output is correct
85 Correct 129 ms 22680 KB Output is correct
86 Correct 131 ms 17092 KB Output is correct
87 Correct 122 ms 16548 KB Output is correct
88 Correct 147 ms 17020 KB Output is correct
89 Correct 118 ms 17028 KB Output is correct
90 Correct 128 ms 16832 KB Output is correct
91 Correct 117 ms 17036 KB Output is correct
92 Correct 117 ms 17404 KB Output is correct
93 Correct 131 ms 19904 KB Output is correct
94 Correct 117 ms 21432 KB Output is correct
95 Correct 115 ms 20132 KB Output is correct
96 Correct 137 ms 18388 KB Output is correct
97 Correct 111 ms 16788 KB Output is correct
98 Correct 119 ms 16276 KB Output is correct
99 Correct 126 ms 16052 KB Output is correct
100 Correct 128 ms 19268 KB Output is correct
101 Correct 123 ms 17216 KB Output is correct
102 Correct 119 ms 16580 KB Output is correct
103 Correct 116 ms 16276 KB Output is correct
104 Correct 98 ms 16548 KB Output is correct
105 Correct 137 ms 25172 KB Output is correct
106 Correct 77 ms 16400 KB Output is correct
107 Correct 80 ms 16396 KB Output is correct
108 Correct 141 ms 29184 KB Output is correct
109 Correct 81 ms 16520 KB Output is correct
110 Correct 141 ms 29644 KB Output is correct
111 Correct 131 ms 15756 KB Output is correct