Submission #924961

# Submission time Handle Problem Language Result Execution time Memory
924961 2024-02-10T07:21:32 Z pan Power Plant (JOI20_power) C++17
0 / 100
2 ms 8028 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, x, y, answer = 0;
string power;
vector<ll> adj[200005];
ll dp[200005], ans[200005];
// dp -> if 0, 1 can be chosen freely under this subtree
vector<ll> visited;

void dfs(ll from)
{
	visited[from] = true;
	ll summ = 0, maxx = 0;
	for (ll u: adj[from])
	{
		if (visited[u]) continue;
		dfs(u);
		summ+=dp[u];
		maxx = max(maxx, dp[u]);
	}
	if (power[from-1]=='1') {ans[from] = max(summ-1, maxx + 1); dp[from] = max(1LL, summ-1);}
	// to make below "activated valid, current from must be broken -> summ-1
	// else all must be disabled, with only current from left activated
	else {ans[from] = dp[from] = summ;}

}
int main()
{
	input(n);
	for (ll i=0; i<n-1; ++i)
	{
		input(x); input(y);
		adj[x].pb(y);
		adj[y].pb(x);
	}
	cin >> power;
	visited.assign(n+1, false);
	dfs(1);
	print(ans[1], '\n');
	return 0;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
power.cpp:56:2: note: in expansion of macro 'input'
   56 |  input(n);
      |  ^~~~~
power.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
power.cpp:59:3: note: in expansion of macro 'input'
   59 |   input(x); input(y);
      |   ^~~~~
power.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
power.cpp:59:13: note: in expansion of macro 'input'
   59 |   input(x); input(y);
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 7856 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Incorrect 2 ms 8028 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 7856 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Incorrect 2 ms 8028 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8028 KB Output is correct
2 Correct 2 ms 7856 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 2 ms 8028 KB Output is correct
5 Correct 2 ms 8028 KB Output is correct
6 Correct 2 ms 8028 KB Output is correct
7 Incorrect 2 ms 8028 KB Output isn't correct
8 Halted 0 ms 0 KB -