Submission #503777

# Submission time Handle Problem Language Result Execution time Memory
503777 2022-01-08T21:47:55 Z Abrar_Al_Samit Power Plant (JOI20_power) C++17
6 / 100
1500 ms 5068 KB
#include<bits/stdc++.h>
using namespace std;
const int MX = 200005;
vector<int>g[MX];
int n;
int dp[MX];
string s;
int ans;
int solve(int v, int p=-1) {
  int &ret = dp[v];
  ret = 0;
  if(s[v]=='0') {
    for(auto u : g[v]) if(u!=p) {
      ret += solve(u, v);
    }
  } else {
    int mx = 0, sum = 0;
    for(auto u : g[v]) if(u!=p) {
      mx = max(mx, solve(u, v));
      sum += solve(u, v);
    }
    mx += 1;
    sum -= 1;
    ans = max({mx, ans, sum});
    ret = max(1, sum);
  }
  return ret;
}
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;
  s = "#" + s;
  cout << max(ans, solve(1)) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 2 ms 4968 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 4920 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 2 ms 4968 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 4920 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Execution timed out 1567 ms 5068 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 5012 KB Output is correct
10 Correct 2 ms 4968 KB Output is correct
11 Correct 2 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 4 ms 4920 KB Output is correct
14 Correct 2 ms 4940 KB Output is correct
15 Correct 2 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 2 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 2 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Execution timed out 1567 ms 5068 KB Time limit exceeded
23 Halted 0 ms 0 KB -