Submission #853401

#TimeUsernameProblemLanguageResultExecution timeMemory
853401stefanneaguPower Plant (JOI20_power)C++17
0 / 100
1 ms348 KiB
#include <iostream> #include <vector> #include <cstring> using namespace std; const int nmax = 2e3 + 2; vector<vector<int>> adj; int sum[nmax], f[nmax], viz[nmax]; string s; void dfs(int i, int cum_from, int add) { if(add == 1) { if(cum_from == 2) { sum[i] = add; } } if(cum_from == 1) { cum_from ++; } for(auto it : adj[i]) { if(!viz[it]) { viz[it] = 1; int curr_add = add; if(s[it] == '1') { curr_add = 1; } if(s[i] == '1' && cum_from == 0) { dfs(it, cum_from + 1, curr_add); } else { dfs(it, cum_from, curr_add); } } } } int main() { int n; cin >> n; adj.resize(n + 1); for(int i = 1; i < n; i ++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); f[a] ++; f[b] ++; } cin >> s; s = '0' + s; for(int i = 1; i <= n; i ++) { memset(viz, 0, sizeof(viz)); viz[i] = 1; if(s[i] == '0') { dfs(i, 0, 0); } else { dfs(i, 0, 1); } } int ans = 0; for(int i = 1; i <= n; i ++) { if(s[i] == '1') { ans ++; int cnt = 0; for(auto it : adj[i]) { if(sum[it]) { cnt ++; } } if(cnt > 1) { ans --; } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...