#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 1000 + 10;
int n, b[N], ans;
string s;
bool mark[N];
vector<int> G[N];
void dfs(int v, int p, int sm) {
if (sm < 0) return;
if (sm == 0) ans++;
for (auto e : G[v])
if (e ^ p)
dfs(e, v, sm + b[e]);
}
int main() {
ios:: sync_with_stdio(0), cin.tie(0);
cin >> n >> s;
for (int i = 0; i < n; i++) b[i + 1] = (s[i] == '('? 1: -1);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
G[u].pb(v);
G[v].pb(u);
}
for (int i = 1; i <= n; i++)
dfs(i, i, b[i]);
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
524 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1260 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
524 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Runtime error |
2 ms |
1260 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |