Submission #931644

#TimeUsernameProblemLanguageResultExecution timeMemory
931644vjudge1Zagrade (COI17_zagrade)C++17
10 / 100
4 ms1260 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...