Submission #503738

# Submission time Handle Problem Language Result Execution time Memory
503738 2022-01-08T19:19:44 Z Abrar_Al_Samit Power Plant (JOI20_power) C++17
0 / 100
4 ms 4996 KB
#include<bits/stdc++.h>
using namespace std;
const int MX = 200005;
vector<int>g[MX];
int n;
int sub[MX];
string s;
int DFS(int v, int p=0) {
  sub[v] = s[v-1]=='1';
  for(int u : g[v]) if(u!=p) {
    sub[v] += DFS(u, v);
  }
  return sub[v];
}
void PlayGround() {
  cin >> n;
  for(int i=1; i<n; ++i) {
    int u, v; cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cin >> s;
  int root = 1;
  for(int i=0; i<n; ++i) if(s[i]=='0') {
    root = i+1;
    break;
  }
  DFS(root);
  int ans = 0;
  for(int i=1; i<=n; ++i) if(sub[i]==1 && s[i-1]=='1') {
    ++ans;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4996 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4996 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4996 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Incorrect 3 ms 4940 KB Output isn't correct
6 Halted 0 ms 0 KB -