hdoj1863 暢通工程

2021-06-08 16:09:00 字數 561 閱讀 5782

此題與hdoj1233解法一樣

#include #include using namespace std;

int city[101];

struct road ;

road road[5051];

int cmp(const road a, const road b)

int find(const int n)

int merge(const int a, const int b)

int main()

sort(road, road+n, cmp);

memset(city, -1, sizeof(city));

sum = count = 0;

for (i = 0; i < n; i++)

if (count == m-1) break;

} if (count != m-1) cout << "?" << endl;

else cout << sum << endl;

} return 0;

}

HDOJ1863 暢通工程

新學習了prim演算法,把之前的dijkstra改了改,d陣列用來存上乙個距離當前節點最近的長度,而不是源點到當前最近的長度就可以了。初始化d為inf,如果條件不夠那和算出來必定 inf 沒考慮溢位,因為我定義的inf並不是很大 題目小坑,把n和m輸入順序反了一下。1 pragma warning ...

HDOJ 1863 暢通工程 普利姆演算法

普利姆演算法是以乙個點為源點,找該源點到下乙個點的最短距離 include include define inf 99999 using namespace std int mp 110 110 int dis 110 bool vis 110 普利姆演算法 void prim int m vis ...

HDU 1863 暢通工程

include include include using namespace std const int maxn 5000 5 int n,m,ans,cnt bool flag struct streat edge maxn int root 105 int find int x void k...