Submission #1049148

#TimeUsernameProblemLanguageResultExecution timeMemory
1049148NeroZeinTransport (COCI19_transport)C++17
26 / 130
1070 ms10672 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define debug(...) #endif const int N = 1e5 + 5; int a[N]; vector<pair<int, int>> g[N]; int dfs(int v, int p, long long fuel) { if (fuel < 0) { return -1; } int ret = 0; fuel += a[v]; for (auto [u, w] : g[v]) { if (u == p) { continue; } ret += 1 + dfs(u, v, fuel - w); } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for(int i = 0; i < n - 1; ++i) { int u, v, w; cin >> u >> v >> w; g[u].push_back({v, w}); g[v].push_back({u, w}); } int ans = 0; for (int i = 1; i <= n; ++i) { ans += dfs(i, i, 0); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...