Submission #419445

# Submission time Handle Problem Language Result Execution time Memory
419445 2021-06-07T06:48:57 Z NintsiChkhaidze Zagrade (COI17_zagrade) C++14
10 / 100
3000 ms 26224 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int N = 300005;
int A[N],S[N];
ll res;
vector <int> v[N];
void dfs(int x,int par){
    A[x] = A[par] + S[x];
    if (A[x] == 0) res++;
    if (A[x] < 0) return;
    for (int j=0;j<v[x].size();j++){
        int to = v[x][j];
        if (to!=par && A[to] >= 0) dfs(to,x);
    }
}
int main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    s = '$' + s;
    for (int i=1;i<=n;i++)
        if (s[i] == '(') S[i] = 1;
        else S[i]= -1;
        
    for (int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b),v[b].pb(a);
    }    
    
    for (int i =1;i<=n;i++){
        if (S[i] == 1) dfs(i,i);
        for (int j=1;j<=n;j++)
            A[j] = 0;
    }
    
    cout<<res;
}

Compilation message

zagrade.cpp: In function 'void dfs(int, int)':
zagrade.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int j=0;j<v[x].size();j++){
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7372 KB Output is correct
2 Correct 16 ms 7380 KB Output is correct
3 Correct 12 ms 7372 KB Output is correct
4 Correct 9 ms 7372 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 16 ms 7372 KB Output is correct
7 Correct 16 ms 7424 KB Output is correct
8 Correct 7 ms 7372 KB Output is correct
9 Correct 12 ms 7428 KB Output is correct
10 Correct 9 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3032 ms 26224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7372 KB Output is correct
2 Correct 16 ms 7380 KB Output is correct
3 Correct 12 ms 7372 KB Output is correct
4 Correct 9 ms 7372 KB Output is correct
5 Correct 10 ms 7424 KB Output is correct
6 Correct 16 ms 7372 KB Output is correct
7 Correct 16 ms 7424 KB Output is correct
8 Correct 7 ms 7372 KB Output is correct
9 Correct 12 ms 7428 KB Output is correct
10 Correct 9 ms 7368 KB Output is correct
11 Execution timed out 3032 ms 26224 KB Time limit exceeded
12 Halted 0 ms 0 KB -