记录编号 |
597393 |
评测结果 |
AAAAAAAAAA |
题目名称 |
魔法药水 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.134 s |
提交时间 |
2024-11-27 14:30:31 |
内存使用 |
4.22 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2010;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n;
int f[N];
ll s[N];
bool v[N];
vector<pii>e[N];
priority_queue<pii,vector<pii>,greater<pii> >q;
void tangbiFHX(){
}
int main(){
freopen("msyrup.in","r",stdin);
freopen("msyrup.out","w",stdout);
n = read();
for(int i = 1;i <= n;i++)f[i] = read(),s[i] = 1;
int x,y,z;
while(~scanf("%d%d%d",&x,&y,&z)){
x++,y++,z++;
e[x].pb({y,z});
if(x != y)e[y].pb({x,z});
}
for(int i = 1;i <= n;i++)q.push({f[i],i});
while(!q.empty()){
int x = q.top().se;q.pop();
if(v[x])continue;v[x] = 1;
for(auto it : e[x]){
int y = it.fi,z = it.se;
if(v[y] && f[z] > f[x] + f[y])f[z] = f[x] + f[y],s[z] = 0;
q.push({f[z],z});
}
}
memset(v,0,sizeof v);
for(int i = 1;i <= n;i++)q.push({f[i],i});
while(!q.empty()){
int x = q.top().se;q.pop();
if(v[x])continue;v[x] = 1;
for(auto it : e[x]){
int y = it.fi,z = it.se;
if(v[y] && f[z] == f[x] + f[y])s[z] += s[x] * s[y];
}
}
printf("%d %lld\n",f[1],s[1]);
return 0;
}
/*
8
10000 1 10000 8 3 5 10000 1
1 4 5
5 6 0
4 5 3
3 2 5
3 7 0
*/