Submission #168274

#TimeUsernameProblemLanguageResultExecution timeMemory
168274egekabasZagrade (COI17_zagrade)C++14
10 / 100
3115 ms224220 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pll; typedef pair<ull, ull> pull; typedef pair<int, int> pii; typedef pair<ld, ld> pld; int n; int a[300009]; vector<int> g[300009]; int ans; unordered_map<int, int> inc[300009]; unordered_map<int, int> out[300009]; void calc(int v, int p){ if(a[v] < 0) out[v][a[v]] = 1; else inc[v][a[v]] = 1; for(auto u : g[v]){ if(u == p) continue; calc(u, v); for(auto k : out[u]){ if(k.ff > 0) continue; ans += inc[v][-k.ff]*k.ss; if(inc[v][-k.ff] == 0) inc[v].erase(-k.ff); } for(auto k : inc[u]){ if(k.ff < 0) continue; ans += out[v][-k.ff]*k.ss; if(out[v][-k.ff] == 0) out[v].erase(-k.ff); } for(auto k : out[u]){ if(a[v] + k.ff <= 0) out[v][a[v]+k.ff] += k.ss; } for(auto k : inc[u]){ if(a[v]+k.ff >= 0) inc[v][a[v]+k.ff] += k.ss; } inc[u].clear(); out[u].clear(); } } int input(){ char c; cin >> c; if(c == '(') return 1; if(c == ')') return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n; for(int i = 1; i <= n; ++i) a[i] = input(); for(int i = 1; i < n; ++i){ int t1, t2; cin >> t1 >> t2; g[t1].pb(t2); g[t2].pb(t1); } calc(1, -1); cout << ans << "\n"; }

Compilation message (stderr)

zagrade.cpp: In function 'int input()':
zagrade.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...