#include<bits/stdc++.h> using namespace std; typedef pair<int, long long> par; vector<par> graf[109]; set<long long> odw[109]; long long P[109]; queue<par> q; void solve() { long long n, m, a, b, c, wyn = -1; par p, p1; cin>>n>>m; for(int i=1; i<=n; i++) { cin>>P[i]; graf[i].clear(); odw[i].clear(); } for(int i=1; i<=m; i++) { cin>>a>>b>>c; graf[a].push_back(par(b, c)); } odw[1].insert(1); q.push(par(1, 1)); while(!q.empty()) { p = q.front(); q.pop(); if(p.first == n && p.second > wyn) wyn = p.second; for(int i=0; i<graf[p.first].size(); i++) { p1 = graf[p.first][i]; a = p.second * p1.second; if(a <= P[p1.first] && odw[p1.first].find(a) == odw[p1.first].end()) { odw[p1.first].insert(a); q.push(par(p1.first, a)); } } } cout<<wyn<<'\n'; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--) solve(); return 0; }
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 | #include<bits/stdc++.h> using namespace std; typedef pair<int, long long> par; vector<par> graf[109]; set<long long> odw[109]; long long P[109]; queue<par> q; void solve() { long long n, m, a, b, c, wyn = -1; par p, p1; cin>>n>>m; for(int i=1; i<=n; i++) { cin>>P[i]; graf[i].clear(); odw[i].clear(); } for(int i=1; i<=m; i++) { cin>>a>>b>>c; graf[a].push_back(par(b, c)); } odw[1].insert(1); q.push(par(1, 1)); while(!q.empty()) { p = q.front(); q.pop(); if(p.first == n && p.second > wyn) wyn = p.second; for(int i=0; i<graf[p.first].size(); i++) { p1 = graf[p.first][i]; a = p.second * p1.second; if(a <= P[p1.first] && odw[p1.first].find(a) == odw[p1.first].end()) { odw[p1.first].insert(a); q.push(par(p1.first, a)); } } } cout<<wyn<<'\n'; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--) solve(); return 0; } |