#include <bits/stdc++.h> using namespace std; long long maxx[207]; vector<pair<long long, long long>> graph[207]; unordered_set<long long> mozliwe[207]; int main() { ios::sync_with_stdio(0); cin.tie(0); long long q; cin >> q; while (q--) { long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { cin >> maxx[i]; graph[i].clear(); mozliwe[i].clear(); } for (long long i = 0; i < m; i++) { long long a, b, c; cin >> a >> b >> c; graph[a].push_back({ b, c }); } queue<pair<long long, long long>> qu; mozliwe[1].insert(1); qu.push({ 1, 1 }); while (!qu.empty()) { auto x = qu.front(); qu.pop(); for (auto y : graph[x.first]) { if (x.second * y.second <= maxx[y.first]) { if (mozliwe[y.first].find(x.second * y.second) == mozliwe[y.first].end()) { mozliwe[y.first].insert(x.second * y.second); qu.push({ y.first, x.second * y.second }); } } } } long long odp = -1; for (auto x : mozliwe[n]) { odp = max(odp, x); } cout << odp << endl; } 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 51 52 53 54 55 56 57 | #include <bits/stdc++.h> using namespace std; long long maxx[207]; vector<pair<long long, long long>> graph[207]; unordered_set<long long> mozliwe[207]; int main() { ios::sync_with_stdio(0); cin.tie(0); long long q; cin >> q; while (q--) { long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { cin >> maxx[i]; graph[i].clear(); mozliwe[i].clear(); } for (long long i = 0; i < m; i++) { long long a, b, c; cin >> a >> b >> c; graph[a].push_back({ b, c }); } queue<pair<long long, long long>> qu; mozliwe[1].insert(1); qu.push({ 1, 1 }); while (!qu.empty()) { auto x = qu.front(); qu.pop(); for (auto y : graph[x.first]) { if (x.second * y.second <= maxx[y.first]) { if (mozliwe[y.first].find(x.second * y.second) == mozliwe[y.first].end()) { mozliwe[y.first].insert(x.second * y.second); qu.push({ y.first, x.second * y.second }); } } } } long long odp = -1; for (auto x : mozliwe[n]) { odp = max(odp, x); } cout << odp << endl; } return 0; } |