#include<bits/stdc++.h> using namespace std; struct gowno{ long long t, a; long long c; }; queue<gowno> Q; long long limit[109]; vector<pair<long long, long long>> D[109]; void solve() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, a, b; long long c; cin >> n >> m; for(int i=1; i<=n; i++) { D[i].clear(); } for(int i=1; i<=n; i++) { cin >> limit[i]; } for(int i=1; i<=m; i++) { cin >> a >> b >> c; D[a].push_back({b, c}); } long long wyn=-1; Q.push({0, 1, 1}); while(!Q.empty()) { if(Q.front().t>(m*30)) { break; } a=Q.front().a; c=Q.front().c; if(a==n) { wyn=max(wyn, c); } for(auto xd:D[a]) { if(c*xd.second <= limit[xd.first]) { Q.push({Q.front().t+1, xd.first, c*xd.second}); } } Q.pop(); } while(!Q.empty()) { Q.pop(); } cout << wyn << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for(int i=1; i<=t; i++) { solve(); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include<bits/stdc++.h> using namespace std; struct gowno{ long long t, a; long long c; }; queue<gowno> Q; long long limit[109]; vector<pair<long long, long long>> D[109]; void solve() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, a, b; long long c; cin >> n >> m; for(int i=1; i<=n; i++) { D[i].clear(); } for(int i=1; i<=n; i++) { cin >> limit[i]; } for(int i=1; i<=m; i++) { cin >> a >> b >> c; D[a].push_back({b, c}); } long long wyn=-1; Q.push({0, 1, 1}); while(!Q.empty()) { if(Q.front().t>(m*30)) { break; } a=Q.front().a; c=Q.front().c; if(a==n) { wyn=max(wyn, c); } for(auto xd:D[a]) { if(c*xd.second <= limit[xd.first]) { Q.push({Q.front().t+1, xd.first, c*xd.second}); } } Q.pop(); } while(!Q.empty()) { Q.pop(); } cout << wyn << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for(int i=1; i<=t; i++) { solve(); } } |