文章

37

粉丝

67

获赞

3

访问

9.2k

头像
继续畅通工程 题解:简单代码来了:
P1311 浙江大学机试题
发布于2024年3月12日 10:36
阅读数 183

#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

//定义结点之间的连接信息
struct node {
    int x;
    int y;
    int fee;
    int status;//修建状况
};

int fa[100];//记录结点的自己的父亲
int sum = 0,ans=0, n;//记录总建路数
struct node va[100];

bool cmp(struct node a, struct node b) {
    return a.fee < b.fee;
}

int find(int x) {
    if (fa[x] == x) return x;
    fa[x] = find(fa[x]);//压缩了路径
    return fa[x];
}

void createRoute(int len) {
    
    for (int i = 0; i < len; i++) {
        if (va[i].status == 0) {//表明未建的路
            //判断两点是否已简接连通了
            int fx = find(va[i].x);
            int fy = find(va[i].y);
            if (fx != fy) {
    &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发