Submission #963805

# Submission time Handle Problem Language Result Execution time Memory
963805 2024-04-15T17:25:09 Z Trisanu_Das Power Plant (JOI20_power) C++17
47 / 100
1500 ms 15532 KB
#include <bits/stdc++.h>
using namespace std;
 
string s;
vector<int> V[200005], dp(200005, 0);
bool vis[200005];
     
void dfs(int v, int root) {
   	vis[v] = 1;
   	dp[v] = s[v - 1] - '0';
   	int rb = 0, rc = 0;
   	for(int i = 0; i < V[v].size(); i++) {
   		int u = V[v][i];
   		if(!vis[u]) {
   			dfs(u, root);
   			rb += dp[u];
   			rc = max(rc, dp[u]);
   		}
   	}
   	if(v == root)
   		dp[v] = rc + 1;
   	else {
   		rb -= s[v-1] - '0';
   		dp[v] = max(dp[v], rb);
   	}
}
    
int main() {
 	int n;
   	cin>>n;
   	for(int i=0; i<(n-1); i++) {
   		int a, b;
   		cin>>a>>b;
   		V[a].push_back(b);
   		V[b].push_back(a);
   	}
   	cin>>s;
   	int ans = 0;
   	for(int i=1; i<=n; i++) {
  		if(s[i-1] == '1') {
   			for(int i = 1; i <= n; i++) dp[i] = vis[i] = 0;
   			dfs(i, i);
   			ans = max(ans, dp[i]);
   		}
   	}
 	cout<<ans;
}

Compilation message

power.cpp: In function 'void dfs(int, int)':
power.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < V[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 3 ms 5724 KB Output is correct
3 Correct 2 ms 5956 KB Output is correct
4 Correct 2 ms 5772 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 3 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 3 ms 5956 KB Output is correct
11 Correct 2 ms 5880 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5720 KB Output is correct
14 Correct 2 ms 5948 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5720 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5720 KB Output is correct
21 Correct 2 ms 5720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 3 ms 5724 KB Output is correct
3 Correct 2 ms 5956 KB Output is correct
4 Correct 2 ms 5772 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 3 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 3 ms 5956 KB Output is correct
11 Correct 2 ms 5880 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5720 KB Output is correct
14 Correct 2 ms 5948 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5720 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5720 KB Output is correct
21 Correct 2 ms 5720 KB Output is correct
22 Correct 57 ms 6020 KB Output is correct
23 Correct 55 ms 6024 KB Output is correct
24 Correct 50 ms 6224 KB Output is correct
25 Correct 30 ms 5980 KB Output is correct
26 Correct 16 ms 6052 KB Output is correct
27 Correct 9 ms 5980 KB Output is correct
28 Correct 4 ms 5980 KB Output is correct
29 Correct 72 ms 6224 KB Output is correct
30 Correct 38 ms 5976 KB Output is correct
31 Correct 54 ms 6024 KB Output is correct
32 Correct 28 ms 5980 KB Output is correct
33 Correct 60 ms 5980 KB Output is correct
34 Correct 36 ms 6228 KB Output is correct
35 Correct 17 ms 5980 KB Output is correct
36 Correct 9 ms 5980 KB Output is correct
37 Correct 39 ms 5980 KB Output is correct
38 Correct 29 ms 5980 KB Output is correct
39 Correct 67 ms 6116 KB Output is correct
40 Correct 35 ms 5980 KB Output is correct
41 Correct 19 ms 5980 KB Output is correct
42 Correct 42 ms 5980 KB Output is correct
43 Correct 9 ms 5980 KB Output is correct
44 Correct 66 ms 6072 KB Output is correct
45 Correct 51 ms 6228 KB Output is correct
46 Correct 30 ms 5980 KB Output is correct
47 Correct 16 ms 5976 KB Output is correct
48 Correct 56 ms 6108 KB Output is correct
49 Correct 63 ms 6232 KB Output is correct
50 Correct 71 ms 5980 KB Output is correct
51 Correct 57 ms 5980 KB Output is correct
52 Correct 52 ms 5980 KB Output is correct
53 Correct 42 ms 5976 KB Output is correct
54 Correct 55 ms 6060 KB Output is correct
55 Correct 56 ms 5980 KB Output is correct
56 Correct 4 ms 5976 KB Output is correct
57 Correct 3 ms 5980 KB Output is correct
58 Correct 41 ms 5980 KB Output is correct
59 Correct 43 ms 6040 KB Output is correct
60 Correct 3 ms 5980 KB Output is correct
61 Correct 3 ms 6232 KB Output is correct
62 Correct 3 ms 5976 KB Output is correct
63 Correct 51 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 3 ms 5724 KB Output is correct
3 Correct 2 ms 5956 KB Output is correct
4 Correct 2 ms 5772 KB Output is correct
5 Correct 2 ms 5720 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 3 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 3 ms 5956 KB Output is correct
11 Correct 2 ms 5880 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5720 KB Output is correct
14 Correct 2 ms 5948 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5720 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 2 ms 5720 KB Output is correct
21 Correct 2 ms 5720 KB Output is correct
22 Correct 57 ms 6020 KB Output is correct
23 Correct 55 ms 6024 KB Output is correct
24 Correct 50 ms 6224 KB Output is correct
25 Correct 30 ms 5980 KB Output is correct
26 Correct 16 ms 6052 KB Output is correct
27 Correct 9 ms 5980 KB Output is correct
28 Correct 4 ms 5980 KB Output is correct
29 Correct 72 ms 6224 KB Output is correct
30 Correct 38 ms 5976 KB Output is correct
31 Correct 54 ms 6024 KB Output is correct
32 Correct 28 ms 5980 KB Output is correct
33 Correct 60 ms 5980 KB Output is correct
34 Correct 36 ms 6228 KB Output is correct
35 Correct 17 ms 5980 KB Output is correct
36 Correct 9 ms 5980 KB Output is correct
37 Correct 39 ms 5980 KB Output is correct
38 Correct 29 ms 5980 KB Output is correct
39 Correct 67 ms 6116 KB Output is correct
40 Correct 35 ms 5980 KB Output is correct
41 Correct 19 ms 5980 KB Output is correct
42 Correct 42 ms 5980 KB Output is correct
43 Correct 9 ms 5980 KB Output is correct
44 Correct 66 ms 6072 KB Output is correct
45 Correct 51 ms 6228 KB Output is correct
46 Correct 30 ms 5980 KB Output is correct
47 Correct 16 ms 5976 KB Output is correct
48 Correct 56 ms 6108 KB Output is correct
49 Correct 63 ms 6232 KB Output is correct
50 Correct 71 ms 5980 KB Output is correct
51 Correct 57 ms 5980 KB Output is correct
52 Correct 52 ms 5980 KB Output is correct
53 Correct 42 ms 5976 KB Output is correct
54 Correct 55 ms 6060 KB Output is correct
55 Correct 56 ms 5980 KB Output is correct
56 Correct 4 ms 5976 KB Output is correct
57 Correct 3 ms 5980 KB Output is correct
58 Correct 41 ms 5980 KB Output is correct
59 Correct 43 ms 6040 KB Output is correct
60 Correct 3 ms 5980 KB Output is correct
61 Correct 3 ms 6232 KB Output is correct
62 Correct 3 ms 5976 KB Output is correct
63 Correct 51 ms 6228 KB Output is correct
64 Execution timed out 1591 ms 15532 KB Time limit exceeded
65 Halted 0 ms 0 KB -