Submission #1294519

#TimeUsernameProblemLanguageResultExecution timeMemory
1294519M_SH_OPower Plant (JOI20_power)C++20
0 / 100
1 ms716 KiB
/*#pragma GCC optimize("O3") #pragma GCC optimization("Ofast,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")*/ #include <bits/stdc++.h> /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>*/ #define ll long long #define ll1 long long #define ull unsigned long long #define dou long double #define str string #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define vpll vector<pair<ll, ll>> #define vbool vector<bool> #define vstr vector<str> #define vvll vector<vll> #define pb push_back #define pf push_front #define endl "\n" #define fr first #define se second // #define sortcmp(a) sort(a.begin(), a.end(), cmp) #define sort(a) sort(a.begin(), a.end()) #define reverse(a) reverse(a.begin(), a.end()) #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; //using namespace __gnu_pbds; const ll INF = 1e18+7; const int lg = 20; const ll MOD = 1e9+7; //const ll MOD2 = 998244353; //const ll MOD3 = 1e6+3; mt19937 rng(1488); ll randll(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); } vvll g; str s; ll dfs(ll v, ll p = -1) { vll a; ll res = 0; for (int i : g[v]) { if (i == p) continue; ll c = dfs(i, v); if (c > 0) { a.pb(c); res += c; } } sort(a); if (s[v-1] == '1') { if (res == 0) res ++; else if (p != -1) res --; else { if (a.size() <= 1) res ++; else if (a.size() == 2 && a[0] == 1) { } else res --; } } return res; } int main() { speed; ll n; cin >> n; g.resize(n+7); for (int i = 0; i < n-1; i ++) { ll a, b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } cin >> s; ll maxl = 0; for (int i = 1; i <= n; i ++) { maxl = max(maxl, dfs(i)); } cout << maxl << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...