Submission #924963

#TimeUsernameProblemLanguageResultExecution timeMemory
924963panPower Plant (JOI20_power)C++17
100 / 100
119 ms32852 KiB
#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;} answer = max(answer, ans[from]); } 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(answer, '\n'); return 0; }

Compilation message (stderr)

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:57:2: note: in expansion of macro 'input'
   57 |  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:60:3: note: in expansion of macro 'input'
   60 |   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:60:13: note: in expansion of macro 'input'
   60 |   input(x); input(y);
      |             ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...