Submission #480291

#TimeUsernameProblemLanguageResultExecution timeMemory
480291MOUF_MAHMALATZagrade (COI17_zagrade)C++14
10 / 100
8 ms7372 KiB
#include<bits/stdc++.h> #define all(s) s.begin(),s.end() #define F first #define S second using namespace std; typedef int ll; ll n,x,y,b[1009],ans; char c; vector<vector<ll> >v; void dfs(ll d,ll p,ll sum) { if(sum<0) return; if(sum==0) ans++; for(auto z:v[d]) if(z!=p) dfs(z,d,sum+b[z]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n; v.resize(n+1); for(ll i=1; i<=n; i++) { cin>>c; if(c=='(') b[i]=1; else b[i]=-1; } for(ll i=1; i<n; i++) { cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } for(ll i=1;i<=n;i++) dfs(i,i,b[i]); cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...