Submission #419445

#TimeUsernameProblemLanguageResultExecution timeMemory
419445NintsiChkhaidzeZagrade (COI17_zagrade)C++14
10 / 100
3032 ms26224 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...