比赛 20241127 评测结果 AAAAAAAAAA
题目名称 魔法药水 最终得分 100
用户昵称 darkMoon 运行时间 0.275 s
代码语言 C++ 内存使用 18.98 MiB
提交时间 2024-11-27 09:26:06
显示代码纯文本
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;
auto IN = freopen("msyrup.in", "r", stdin);
auto OUT = freopen("msyrup.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1005;
int n = mread(), f[N], s[N], to[N][N], e[N], la[N][N];
signed main(){
    memset(la, 0x3f ,sizeof(la));
    memset(to, -1, sizeof(to));
    for(int i = 0; i < n; i ++){
        cin >> f[i];
        s[i] = 1;
    }
    {
        int a, b, c;
        while(cin >> a >> b >> c){
            to[a][b] = to[b][a] = c;
        }
    }
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
    for(int i = 0; i < n; i ++){
        q.push(mp(f[i], i));
    }
    while(q.size()){
        int x = q.top().se;
        q.pop();
        if(e[x]){
            continue;
        }
        e[x] = 1;
        for(int y = 0; y < n; y ++){
            int z = to[x][y];
            if(z != -1){
                if(f[x] + f[y] < f[z]){
                    f[z] = f[x] + f[y];
                    s[z] = 0;
                    q.push(mp(f[z], z));
                }
            }
        }
    }
    for(int i = 0; i < n; i ++){
        q.push(mp(f[i], i));
    }
    memset(e, 0, sizeof(e));
    while(q.size()){
        int x = q.top().se;
        q.pop();
        if(e[x]){
            continue;
        }
        e[x] = 1;
        for(int y = 0; y < n; y ++){
            if(f[y] < f[x] || (f[x] == f[y] && y <= x)){
                int z = to[x][y];
                if(z != -1){
                    if(f[x] + f[y] == f[z]){
                        s[z] += s[x] * s[y];
                    }
                }
            }
        }
    }
    printf("%lld %lld", f[0], s[0]);
    return 0;
}