# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
250865 |
2020-07-19T10:20:08 Z |
VEGAnn |
Zagrade (COI17_zagrade) |
C++14 |
|
3000 ms |
32780 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int N = 300100;
vector<int> g[N];
int ad[N], n, ans = 0;
string s;
void dfs(int v, int p, int sm){
if (sm < 0) return;
if (sm == 0)
ans++;
for (int u : g[v]){
if (p == u) continue;
dfs(u, v, sm + ad[u]);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> s;
for (int i = 0; i < n; i++)
ad[i] = (s[i] == '(' ? 1 : -1);
for (int i = 1; i < n; i++) {
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y);
g[y].PB(x);
}
for (int i = 0; i < n; i++)
dfs(i, -1, ad[i]);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7424 KB |
Output is correct |
2 |
Correct |
12 ms |
7424 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
7 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
12 ms |
7424 KB |
Output is correct |
7 |
Correct |
11 ms |
7424 KB |
Output is correct |
8 |
Correct |
6 ms |
7424 KB |
Output is correct |
9 |
Correct |
12 ms |
7424 KB |
Output is correct |
10 |
Correct |
7 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2777 ms |
25292 KB |
Output is correct |
2 |
Correct |
123 ms |
18572 KB |
Output is correct |
3 |
Execution timed out |
3066 ms |
32780 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7424 KB |
Output is correct |
2 |
Correct |
12 ms |
7424 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
7 ms |
7424 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
12 ms |
7424 KB |
Output is correct |
7 |
Correct |
11 ms |
7424 KB |
Output is correct |
8 |
Correct |
6 ms |
7424 KB |
Output is correct |
9 |
Correct |
12 ms |
7424 KB |
Output is correct |
10 |
Correct |
7 ms |
7424 KB |
Output is correct |
11 |
Correct |
2777 ms |
25292 KB |
Output is correct |
12 |
Correct |
123 ms |
18572 KB |
Output is correct |
13 |
Execution timed out |
3066 ms |
32780 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |