Submission #763288

#TimeUsernameProblemLanguageResultExecution timeMemory
763288vjudge1Power Plant (JOI20_power)C++17
0 / 100
1 ms2644 KiB
#include<bits/stdc++.h> using namespace std; int n, x, y, ans = 0; pair<int, int> cnt[100001]; vector<int> vec[100001]; string s; bool visited[100001]; void dfs(int x, bool ok) { visited[x] = true; if(s[x - 1] == '1' && x != cnt[n].second) { ok = 1; ++ans; return; } for(int c : vec[x]) { if(!visited[c]) { dfs(c, ok); } if(x == cnt[n].second) ok = 0; if(ok) return; } } int main() { cin >> n; for(int i = 1; i <= n; ++i) { cnt[i] = {0, 0}; } for(int i = 1; i < n; ++i) { cin >> x >> y; ++cnt[x].first; ++cnt[y].first; cnt[x].second = x; cnt[y].second = y; vec[x].push_back(y); vec[y].push_back(x); } sort(cnt + 1, cnt + n + 1); cin >> s; dfs(cnt[n].second, 0); cout << ans - s[n - 1] + '0'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...