题解 | 小红的魔法药剂

小红的魔法药剂

https://www.nowcoder.com/practice/1ede2daa3ab445bc8ac8ea62b6ca8201

#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);

    int a[200005];
    int res = 0;
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (int i = 1; i <= n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        res += (a[i] < a[x] + a[y]) ? a[i] : a[x] + a[y];
    }
    printf("%d", res);

    return 0;
}

全部评论

相关推荐

xtu大迫杰:偶遇校友,祝校友offer打牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务