Submission #853370

#TimeUsernameProblemLanguageResultExecution timeMemory
853370stefanneaguPower Plant (JOI20_power)C++17
0 / 100
0 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 add) { sum[i] += add; for(auto it : adj[i]) { if(!viz[it]) { viz[it] = 1; if(s[it] == '1') { add = 1; } dfs(it, 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 ++) { if(f[i] == 1) { memset(viz, 0, sizeof(viz)); dfs(i, 0); } } 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...