Submission #453248

# Submission time Handle Problem Language Result Execution time Memory
453248 2021-08-04T10:04:29 Z fuad27 Power Plant (JOI20_power) C++14
47 / 100
1500 ms 15500 KB
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 2e5 + 4;
    string s;
    vector<int> V[N], dp(N, 0);
    bool vis[N];
     
    void clear(int n) {
    	for(int i=1; i<=n; i++) {
    		dp[i] = 0;
    		vis[i] = 0;
    	}
    }
     
    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<(int) 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') {
    			clear(n);
    			dfs(i, i);
    			ans = max(ans, dp[i]);
    		}
    	}
    	cout<<ans;
    }
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5796 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5760 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5788 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 4 ms 5772 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 4 ms 5708 KB Output is correct
13 Correct 4 ms 5708 KB Output is correct
14 Correct 4 ms 5708 KB Output is correct
15 Correct 4 ms 5708 KB Output is correct
16 Correct 4 ms 5708 KB Output is correct
17 Correct 4 ms 5708 KB Output is correct
18 Correct 4 ms 5796 KB Output is correct
19 Correct 5 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 4 ms 5708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5796 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5760 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5788 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 4 ms 5772 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 4 ms 5708 KB Output is correct
13 Correct 4 ms 5708 KB Output is correct
14 Correct 4 ms 5708 KB Output is correct
15 Correct 4 ms 5708 KB Output is correct
16 Correct 4 ms 5708 KB Output is correct
17 Correct 4 ms 5708 KB Output is correct
18 Correct 4 ms 5796 KB Output is correct
19 Correct 5 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 4 ms 5708 KB Output is correct
22 Correct 109 ms 5860 KB Output is correct
23 Correct 96 ms 5864 KB Output is correct
24 Correct 83 ms 5836 KB Output is correct
25 Correct 56 ms 5836 KB Output is correct
26 Correct 31 ms 5836 KB Output is correct
27 Correct 16 ms 5836 KB Output is correct
28 Correct 6 ms 5836 KB Output is correct
29 Correct 148 ms 6044 KB Output is correct
30 Correct 66 ms 5964 KB Output is correct
31 Correct 98 ms 5836 KB Output is correct
32 Correct 52 ms 5804 KB Output is correct
33 Correct 96 ms 5800 KB Output is correct
34 Correct 54 ms 5808 KB Output is correct
35 Correct 29 ms 5880 KB Output is correct
36 Correct 15 ms 5876 KB Output is correct
37 Correct 72 ms 5868 KB Output is correct
38 Correct 52 ms 5836 KB Output is correct
39 Correct 120 ms 5948 KB Output is correct
40 Correct 63 ms 5964 KB Output is correct
41 Correct 33 ms 5968 KB Output is correct
42 Correct 59 ms 5836 KB Output is correct
43 Correct 21 ms 5836 KB Output is correct
44 Correct 109 ms 5836 KB Output is correct
45 Correct 76 ms 5900 KB Output is correct
46 Correct 53 ms 5836 KB Output is correct
47 Correct 30 ms 5864 KB Output is correct
48 Correct 100 ms 5964 KB Output is correct
49 Correct 100 ms 5964 KB Output is correct
50 Correct 97 ms 5836 KB Output is correct
51 Correct 99 ms 5904 KB Output is correct
52 Correct 101 ms 5800 KB Output is correct
53 Correct 76 ms 5920 KB Output is correct
54 Correct 97 ms 5916 KB Output is correct
55 Correct 101 ms 5836 KB Output is correct
56 Correct 6 ms 5836 KB Output is correct
57 Correct 6 ms 5964 KB Output is correct
58 Correct 68 ms 5836 KB Output is correct
59 Correct 72 ms 5804 KB Output is correct
60 Correct 6 ms 5964 KB Output is correct
61 Correct 5 ms 5796 KB Output is correct
62 Correct 7 ms 5964 KB Output is correct
63 Correct 93 ms 5808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5796 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5760 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5788 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 4 ms 5772 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 4 ms 5708 KB Output is correct
13 Correct 4 ms 5708 KB Output is correct
14 Correct 4 ms 5708 KB Output is correct
15 Correct 4 ms 5708 KB Output is correct
16 Correct 4 ms 5708 KB Output is correct
17 Correct 4 ms 5708 KB Output is correct
18 Correct 4 ms 5796 KB Output is correct
19 Correct 5 ms 5708 KB Output is correct
20 Correct 4 ms 5708 KB Output is correct
21 Correct 4 ms 5708 KB Output is correct
22 Correct 109 ms 5860 KB Output is correct
23 Correct 96 ms 5864 KB Output is correct
24 Correct 83 ms 5836 KB Output is correct
25 Correct 56 ms 5836 KB Output is correct
26 Correct 31 ms 5836 KB Output is correct
27 Correct 16 ms 5836 KB Output is correct
28 Correct 6 ms 5836 KB Output is correct
29 Correct 148 ms 6044 KB Output is correct
30 Correct 66 ms 5964 KB Output is correct
31 Correct 98 ms 5836 KB Output is correct
32 Correct 52 ms 5804 KB Output is correct
33 Correct 96 ms 5800 KB Output is correct
34 Correct 54 ms 5808 KB Output is correct
35 Correct 29 ms 5880 KB Output is correct
36 Correct 15 ms 5876 KB Output is correct
37 Correct 72 ms 5868 KB Output is correct
38 Correct 52 ms 5836 KB Output is correct
39 Correct 120 ms 5948 KB Output is correct
40 Correct 63 ms 5964 KB Output is correct
41 Correct 33 ms 5968 KB Output is correct
42 Correct 59 ms 5836 KB Output is correct
43 Correct 21 ms 5836 KB Output is correct
44 Correct 109 ms 5836 KB Output is correct
45 Correct 76 ms 5900 KB Output is correct
46 Correct 53 ms 5836 KB Output is correct
47 Correct 30 ms 5864 KB Output is correct
48 Correct 100 ms 5964 KB Output is correct
49 Correct 100 ms 5964 KB Output is correct
50 Correct 97 ms 5836 KB Output is correct
51 Correct 99 ms 5904 KB Output is correct
52 Correct 101 ms 5800 KB Output is correct
53 Correct 76 ms 5920 KB Output is correct
54 Correct 97 ms 5916 KB Output is correct
55 Correct 101 ms 5836 KB Output is correct
56 Correct 6 ms 5836 KB Output is correct
57 Correct 6 ms 5964 KB Output is correct
58 Correct 68 ms 5836 KB Output is correct
59 Correct 72 ms 5804 KB Output is correct
60 Correct 6 ms 5964 KB Output is correct
61 Correct 5 ms 5796 KB Output is correct
62 Correct 7 ms 5964 KB Output is correct
63 Correct 93 ms 5808 KB Output is correct
64 Execution timed out 1574 ms 15500 KB Time limit exceeded
65 Halted 0 ms 0 KB -