比赛 20241127 评测结果 WAAAAWAAAA
题目名称 魔法药水 最终得分 80
用户昵称 ┭┮﹏┭┮ 运行时间 0.136 s
代码语言 C++ 内存使用 4.19 MiB
提交时间 2024-11-27 09:37:09
显示代码纯文本
#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] = 1;
			else if(v[y] && f[z] == f[x] + f[y])s[z] += s[x] * s[y];
			q.push({f[z],z});
		}
	}
	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
*/