88pts WA on #12 help!!!!!!!!!
查看原帖
88pts WA on #12 help!!!!!!!!!
1049051
JiuZhE66666楼主2023/12/26 20:48
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct unit
{
    ll x,y;
};
vector<unit> G[1005];
ll cost[1005]={0};
ll num[1005];
ll vis[1005]={0};
void ss(ll now)
{
    if(vis[now])return;
    else vis[now]=1;
    for(ll i=0;i<G[now].size();i++)
    {
        ll x=G[now][i].x;
        ll y=G[now][i].y;
        ss(x); ss(y);
        if(cost[x]+cost[y]<cost[now])
        {
            cost[now]=cost[x]+cost[y];
            num[now]=num[x]*num[y];
        }
        else if(cost[x]+cost[y]==cost[now])
        {
            num[now]+=num[x]*num[y];
        }
    }
}
int main()
{
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>cost[i];
        num[i]=1;
    }
    ll x,y,z;
    while(~scanf("%d%d%d",&x,&y,&z)) G[z].push_back({x,y});
    ss(0);
    printf("%d %d",cost[0],num[0]);
    return 0;
}

2023/12/26 20:48
加载中...