# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
894906 |
2023-12-29T07:51:46 Z |
vjudge1 |
Zagrade (COI17_zagrade) |
C++11 |
|
60 ms |
21504 KB |
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 3 * 1e5 + 10;
const ll mod = 1e9 + 7;
ll um(ll a, ll b){
return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll add(ll a, ll b){
return (1LL * a + b) % mod;
}
ll binpow(ll x, ll step){
ll res = 1LL;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
vector <int> q[N];
bool arr[N];
int ans, n;
void over(){
}
void dfs(int v, int p, int cnt){
if(cnt == 0) ans++;
for(auto u : q[v]){
if(u == p) continue;
if(arr[u]) dfs(u, v, cnt + 1);
else{
if(cnt > 0) dfs(u, v, cnt - 1);
}
}
}
void subtask1(){
for(int i = 1; i <= n; i++){
if(arr[i] == true) dfs(i, -1, 1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> n >> s;
for(int i = 0; i < n; i++){
if(s[i] == '(') arr[i + 1] = true;
}
for(int i = 0, a, b; i < n - 1; i++){
cin >> a >> b;
q[a].pb(b);
q[b].pb(a);
}
if(n <= 1000){
subtask1();
} else{
over();
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7516 KB |
Output is correct |
2 |
Correct |
6 ms |
7516 KB |
Output is correct |
3 |
Correct |
5 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7632 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
6 ms |
7512 KB |
Output is correct |
7 |
Correct |
5 ms |
7516 KB |
Output is correct |
8 |
Correct |
3 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7664 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
21504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7516 KB |
Output is correct |
2 |
Correct |
6 ms |
7516 KB |
Output is correct |
3 |
Correct |
5 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7632 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
6 ms |
7512 KB |
Output is correct |
7 |
Correct |
5 ms |
7516 KB |
Output is correct |
8 |
Correct |
3 ms |
7516 KB |
Output is correct |
9 |
Correct |
4 ms |
7664 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Incorrect |
60 ms |
21504 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |