Submission #931644

# Submission time Handle Problem Language Result Execution time Memory
931644 2024-02-22T07:43:18 Z vjudge1 Zagrade (COI17_zagrade) C++17
10 / 100
4 ms 1260 KB
#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;
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -