Submission #660600

#TimeUsernameProblemLanguageResultExecution timeMemory
660600sandry24Power Plant (JOI20_power)C++17
0 / 100
4 ms4948 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second vector<vi> adj(200005); vector<bool> visited(200005); string hasGen; int temp = 0; bool many = false; void dfs(int x, int p){ visited[x] = 1; int branch = 0; for(auto i : adj[x]){ int temp2 = temp; if(hasGen[i-1] == '1' && i != p) temp++; if(!visited[i] && hasGen[i-1] != '1'){ dfs(i, x); } if(temp2 != temp) branch++; } if(branch >= 2) many = true; else many = false; } void solve(){ int n; cin >> n; for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } cin >> hasGen; int ans = 1; for(int i = 1; i <= n; i++){ temp = 0; many = false; if(!visited[i]){ //cout << i << ' '; dfs(i, -1); if(hasGen[i-1] == '1') temp++; //cout << temp << '\n'; } if(many) temp -= 2; ans = max(ans, temp); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...