Submission #992283

# Submission time Handle Problem Language Result Execution time Memory
992283 2024-06-04T08:23:50 Z hariaakas646 Power Plant (JOI20_power) C++17
100 / 100
111 ms 44180 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for(int i=j; i<k; i++)
#define frange(i, k) forr(i, 0, k)
#define mp make_pair
#define pb push_back
#define all(vec) vec.begin(), vec.end()
#define f first
#define s second

typedef long long lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef vector<lli> vll;
typedef long double ld;

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void usaco() {
	freopen("/home/student_visitors/v_hari_aakash_k/Desktop/IOITC_practice/input.in", "r", stdin);
}

vvi graph;
vi dp1, dp2;
vi plt;

void dfs(int x, int p) {
	vi v1, v2;
	int t1 = 0, t2 = 0;
	for(auto e : graph[x]) {
		if(e != p) {

			dfs(e, x);
			v1.pb(dp1[e]);
			v2.pb(dp2[e]);
			t1 += dp1[e];
			t2 += dp2[e];
		}
	}
	sort(all(v1), greater<>());
	sort(all(v2), greater<>());
	dp1[x] = dp2[x] = plt[x];
	if(v1.size()) {
		dp1[x] = max({dp1[x], v1[0], v2[0] + plt[x], t2 - plt[x]});
		dp2[x] = max({dp2[x], v2[0] - plt[x], t2 - plt[x]});
	}
	// printf("%d %d %d\n", x, dp1[x], dp2[x]);
}

int main() {
	// usaco();
	fastio();
	int n;
	cin >> n;

	graph = vvi(n+1);

	frange(i, n-1) {
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}

	string str;
	cin >> str;
	dp1 = dp2 = plt = vi(n+1);
	forr(i, 1, n+1) {
		plt[i] = (str[i-1] - '0');
	}
	dfs(1, 0);
	printf("%d\n", dp1[1]);
}

Compilation message

power.cpp: In function 'void usaco()':
power.cpp:34:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  freopen("/home/student_visitors/v_hari_aakash_k/Desktop/IOITC_practice/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 612 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 668 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 640 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 600 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 612 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 668 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 640 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 600 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 70 ms 16912 KB Output is correct
65 Correct 69 ms 16952 KB Output is correct
66 Correct 91 ms 16768 KB Output is correct
67 Correct 66 ms 16784 KB Output is correct
68 Correct 65 ms 16764 KB Output is correct
69 Correct 75 ms 16916 KB Output is correct
70 Correct 67 ms 16940 KB Output is correct
71 Correct 62 ms 16800 KB Output is correct
72 Correct 71 ms 16784 KB Output is correct
73 Correct 83 ms 42128 KB Output is correct
74 Correct 89 ms 42136 KB Output is correct
75 Correct 68 ms 16788 KB Output is correct
76 Correct 67 ms 16768 KB Output is correct
77 Correct 68 ms 16788 KB Output is correct
78 Correct 72 ms 16788 KB Output is correct
79 Correct 63 ms 16800 KB Output is correct
80 Correct 68 ms 16780 KB Output is correct
81 Correct 61 ms 18376 KB Output is correct
82 Correct 61 ms 17448 KB Output is correct
83 Correct 78 ms 27880 KB Output is correct
84 Correct 74 ms 32672 KB Output is correct
85 Correct 75 ms 32032 KB Output is correct
86 Correct 71 ms 19784 KB Output is correct
87 Correct 66 ms 18436 KB Output is correct
88 Correct 66 ms 18636 KB Output is correct
89 Correct 65 ms 18844 KB Output is correct
90 Correct 66 ms 18164 KB Output is correct
91 Correct 65 ms 18844 KB Output is correct
92 Correct 66 ms 19328 KB Output is correct
93 Correct 60 ms 24996 KB Output is correct
94 Correct 73 ms 28024 KB Output is correct
95 Correct 64 ms 25676 KB Output is correct
96 Correct 67 ms 21744 KB Output is correct
97 Correct 58 ms 18412 KB Output is correct
98 Correct 67 ms 17344 KB Output is correct
99 Correct 65 ms 17040 KB Output is correct
100 Correct 88 ms 23696 KB Output is correct
101 Correct 72 ms 19480 KB Output is correct
102 Correct 60 ms 18016 KB Output is correct
103 Correct 66 ms 17448 KB Output is correct
104 Correct 60 ms 20168 KB Output is correct
105 Correct 78 ms 35764 KB Output is correct
106 Correct 44 ms 19908 KB Output is correct
107 Correct 46 ms 19908 KB Output is correct
108 Correct 84 ms 43664 KB Output is correct
109 Correct 55 ms 20148 KB Output is correct
110 Correct 111 ms 44180 KB Output is correct
111 Correct 58 ms 16800 KB Output is correct