#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<set>
#include<queue>
using namespace std;
constexpr auto NM = 205;
long long P[NM];
set<pair<int, long long>> sasiedzi[NM];
set<pair<int, long long>> visible;
bool wasVisible(pair<int, long long> vertex) {
auto it = visible.find(vertex);
return it != visible.end();
}
int main() {
int T;
scanf("%d", &T);
for (int t = 0; t < T; t++) {
for (int i = 0; i < NM; i++) {
sasiedzi[i].clear();
}
visible.clear();
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%lld", &P[i]);
}
for (int i = 1; i <= m; i++) {
int a, b;
long long w;
scanf("%d %d %lld", &a, &b, &w);
if (a != b || w != 1L) {
sasiedzi[a].insert(make_pair(b, w));
}
}
long long result = -1;
queue<pair<int, long long>> q;
auto start = make_pair(1, 1);
q.push(start);
visible.insert(start);
while (!q.empty()) {
auto current = q.front();
q.pop();
if (current.first == n) {
result = max(result, current.second);
}
for (auto it = sasiedzi[current.first].begin(); it != sasiedzi[current.first].end(); it++) {
long long nowa_moc = current.second * it->second;
if (nowa_moc <= P[it->first]) {
auto nowy = make_pair(it->first, nowa_moc);
if (!wasVisible(nowy)) {
q.push(nowy);
visible.insert(nowy);
}
}
}
}
printf("%lld\n", result);
}
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<vector> #include<set> #include<queue> using namespace std; constexpr auto NM = 205; long long P[NM]; set<pair<int, long long>> sasiedzi[NM]; set<pair<int, long long>> visible; bool wasVisible(pair<int, long long> vertex) { auto it = visible.find(vertex); return it != visible.end(); } int main() { int T; scanf("%d", &T); for (int t = 0; t < T; t++) { for (int i = 0; i < NM; i++) { sasiedzi[i].clear(); } visible.clear(); int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%lld", &P[i]); } for (int i = 1; i <= m; i++) { int a, b; long long w; scanf("%d %d %lld", &a, &b, &w); if (a != b || w != 1L) { sasiedzi[a].insert(make_pair(b, w)); } } long long result = -1; queue<pair<int, long long>> q; auto start = make_pair(1, 1); q.push(start); visible.insert(start); while (!q.empty()) { auto current = q.front(); q.pop(); if (current.first == n) { result = max(result, current.second); } for (auto it = sasiedzi[current.first].begin(); it != sasiedzi[current.first].end(); it++) { long long nowa_moc = current.second * it->second; if (nowa_moc <= P[it->first]) { auto nowy = make_pair(it->first, nowa_moc); if (!wasVisible(nowy)) { q.push(nowy); visible.insert(nowy); } } } } printf("%lld\n", result); } return 0; } |
English