Submission #236660

#TimeUsernameProblemLanguageResultExecution timeMemory
236660andreiomdTransport (COCI19_transport)C++11
26 / 130
153 ms9336 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair < int, int > PII; typedef pair < PII, ll > Type; const int NMAX = 1e5 + 5; int N, A[NMAX]; vector < PII > G[NMAX]; long long ans = 0; queue < Type > Q; static inline void Read () { ios_base :: sync_with_stdio(false); cin.tie(nullptr); cin >> N; for(int i = 1; i <= N; ++i) cin >> A[i]; for(int i = 1; i < N; ++i) { int X = 0, Y = 0, C = 0; cin >> X >> Y >> C; G[X].push_back({C, Y}); G[Y].push_back({C, X}); } return; } static inline void Brute_Force () { for(int i = 1; i <= N; ++i) { Q.push({{i, 0}, A[i]}); while(!Q.empty()) { int Node = Q.front().first.first, from = Q.front().first.second; long long x = Q.front().second; Q.pop(); for(auto it : G[Node]) if(it.second != from && x >= it.first) { ++ans; Q.push({{it.second, Node}, x - 1LL * it.first + 1LL * A[it.second]}); } } } cout << ans << '\n'; return; } int main() { Read(); if(N <= 5e3) Brute_Force(); 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...