Submission #480302

# Submission time Handle Problem Language Result Execution time Memory
480302 2021-10-15T15:01:53 Z BERNARB01 Zagrade (COI17_zagrade) C++17
10 / 100
31 ms 12080 KB
#include <bits/stdc++.h>

using namespace std;

const int N = (int) 1e5 + 9;

int n;
string a;
vector<int> g[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> a;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n <= 1000) {
    function<int(int, int, int)> DFS = [&](int v, int pr, int bal) {
      bal += (a[v] == '(') - (a[v] == ')');
      if (bal < 0) {
        return 0;
      }
      int ret = !bal;
      for (int u : g[v]) {
        if (u == pr) {
          continue;
        }
        ret += DFS(u, v, bal);
      }
      return ret;
    };
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += DFS(i, -1, 0);
    }
    cout << ans << '\n';
  } else {
    assert(false);
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2636 KB Output is correct
2 Correct 12 ms 2636 KB Output is correct
3 Correct 8 ms 2636 KB Output is correct
4 Correct 6 ms 2636 KB Output is correct
5 Correct 8 ms 2636 KB Output is correct
6 Correct 10 ms 2636 KB Output is correct
7 Correct 9 ms 2696 KB Output is correct
8 Correct 4 ms 2636 KB Output is correct
9 Correct 6 ms 2636 KB Output is correct
10 Correct 6 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 12080 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2636 KB Output is correct
2 Correct 12 ms 2636 KB Output is correct
3 Correct 8 ms 2636 KB Output is correct
4 Correct 6 ms 2636 KB Output is correct
5 Correct 8 ms 2636 KB Output is correct
6 Correct 10 ms 2636 KB Output is correct
7 Correct 9 ms 2696 KB Output is correct
8 Correct 4 ms 2636 KB Output is correct
9 Correct 6 ms 2636 KB Output is correct
10 Correct 6 ms 2636 KB Output is correct
11 Runtime error 31 ms 12080 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -