佳佳的魔法药水
作者:
logos--
,
2023-08-17 13:47:00
,
所有人可见
,
阅读 114
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int N = 1010, M = 10010;
constexpr int inf = 1E18, mod = 100003;
int n, m, ans[N], cost[N], d[N][N];
bool vis[N];
inline void Main() {
int n; cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> cost[i];
ans[i] = 1;
}
int a, b, c;
while(cin >> a >> b >> c) {
d[a + 1][b + 1] = c + 1;
d[b + 1][a + 1] = c + 1;
}
for (int i = 1; i < n; i ++) {
int t = -1;
for (int j = 1; j <= n; j ++) {
if(!vis[j] && (t == -1 || cost[t] > cost[j])) {
t = j;
}
}
vis[t] = true;
for (int j = 1; j <= n; j ++) {
if(vis[j] && d[t][j]) {
if(cost[t] + cost[j] == cost[d[t][j]]) {
ans[d[t][j]] += ans[t] * ans[j];
}
if(cost[t] + cost[j] < cost[d[t][j]]) {
cost[d[t][j]] = cost[t] + cost[j];
ans[d[t][j]] = ans[t] * ans[j];
}
}
}
}
cout << cost[1] << " " << ans[1] << '\n';
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T = 1;
while(T --) Main();
return 0;
}