Submission #992254

# Submission time Handle Problem Language Result Execution time Memory
992254 2024-06-04T07:40:06 Z hariaakas646 Power Plant (JOI20_power) C++17
0 / 100
1 ms 464 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], 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 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 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -