Submission #763194

# Submission time Handle Problem Language Result Execution time Memory
763194 2023-06-22T06:17:24 Z vjudge1 Power Plant (JOI20_power) C++17
100 / 100
131 ms 26524 KB
#include <bits/stdc++.h>
using namespace std;

// Write down the limits of the problem here

const int NM = 2e5+5;
vector<int> G[NM];
int is_power_gen[NM];
int dp[NM];
int res = 0;

void dfs(int v, int p){
	int best_subtree = 0;
	for (int u : G[v]){
		if (u == p) continue;
		dfs(u, v);
		best_subtree = max(best_subtree, dp[u]);
		dp[v] += dp[u];
	}
	if (is_power_gen[v]){
		res = max(res, best_subtree + 1);
		dp[v] = max(1, dp[v] - 1);
	}
	res = max(res, dp[v]);
}
int main() {
	// Try to avoid cin, cout :)

	int tc = 1; // scanf("%d", &tc);
	while(tc--) {
		/// Your solution here
		int n;
		scanf("%d", &n);
		for (int i = 0; i < n - 1; i++){
			int x, y;
			scanf("%d%d", &x, &y);
			G[x].push_back(y);
			G[y].push_back(x);
		}
		for (int i = 1; i <= n; i++){
			char c;
			do { c = getchar(); } while (isspace(c));
			is_power_gen[i] = (c == '1');
		}
		dfs(1, -1);
		printf("%d", res);
	}
	return 0;
}

/*
 * Ermm don't underestimate Div2A, pls...
 * 
 * If there isn't a clear-cut approach for your program, DO NOT CODE YET!
 *
 * Write down some notes for more complicated problems
 * 
 * Also, please, CP isn't supposed to be complicated
 * 
**/

Compilation message

power.cpp: In function 'int main()':
power.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
power.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |    scanf("%d%d", &x, &y);
      |    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5092 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5064 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 2 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5076 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 3 ms 5076 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5204 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5092 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 4 ms 5076 KB Output is correct
39 Correct 4 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5064 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 4 ms 5076 KB Output is correct
49 Correct 3 ms 5076 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 2 ms 5076 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5076 KB Output is correct
55 Correct 3 ms 5076 KB Output is correct
56 Correct 3 ms 5076 KB Output is correct
57 Correct 3 ms 5204 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Correct 3 ms 5076 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5076 KB Output is correct
62 Correct 4 ms 5076 KB Output is correct
63 Correct 3 ms 5076 KB Output is correct
64 Correct 70 ms 12836 KB Output is correct
65 Correct 75 ms 12880 KB Output is correct
66 Correct 73 ms 12924 KB Output is correct
67 Correct 72 ms 12868 KB Output is correct
68 Correct 83 ms 12876 KB Output is correct
69 Correct 119 ms 12876 KB Output is correct
70 Correct 71 ms 12908 KB Output is correct
71 Correct 73 ms 12864 KB Output is correct
72 Correct 79 ms 12832 KB Output is correct
73 Correct 93 ms 25444 KB Output is correct
74 Correct 111 ms 25596 KB Output is correct
75 Correct 76 ms 12804 KB Output is correct
76 Correct 108 ms 12792 KB Output is correct
77 Correct 71 ms 12724 KB Output is correct
78 Correct 72 ms 12748 KB Output is correct
79 Correct 75 ms 12756 KB Output is correct
80 Correct 89 ms 13008 KB Output is correct
81 Correct 63 ms 13108 KB Output is correct
82 Correct 65 ms 13028 KB Output is correct
83 Correct 116 ms 18004 KB Output is correct
84 Correct 86 ms 20068 KB Output is correct
85 Correct 131 ms 19744 KB Output is correct
86 Correct 80 ms 14156 KB Output is correct
87 Correct 90 ms 13648 KB Output is correct
88 Correct 87 ms 14132 KB Output is correct
89 Correct 72 ms 14160 KB Output is correct
90 Correct 73 ms 13896 KB Output is correct
91 Correct 90 ms 14084 KB Output is correct
92 Correct 84 ms 14492 KB Output is correct
93 Correct 75 ms 16968 KB Output is correct
94 Correct 91 ms 18644 KB Output is correct
95 Correct 79 ms 17196 KB Output is correct
96 Correct 93 ms 15488 KB Output is correct
97 Correct 68 ms 13968 KB Output is correct
98 Correct 69 ms 13468 KB Output is correct
99 Correct 70 ms 13236 KB Output is correct
100 Correct 76 ms 16412 KB Output is correct
101 Correct 78 ms 14420 KB Output is correct
102 Correct 90 ms 13672 KB Output is correct
103 Correct 74 ms 13388 KB Output is correct
104 Correct 51 ms 12792 KB Output is correct
105 Correct 89 ms 22272 KB Output is correct
106 Correct 51 ms 13576 KB Output is correct
107 Correct 49 ms 13600 KB Output is correct
108 Correct 114 ms 26220 KB Output is correct
109 Correct 53 ms 12748 KB Output is correct
110 Correct 93 ms 26524 KB Output is correct
111 Correct 83 ms 12696 KB Output is correct