资源简介
PAT顶级题目题解,用到的算法为并查集。去掉某一个城市,先利用正在使用的公路,对各个城市进行合并。然后利用被摧毁的公路,对城市进行合并,并把所需的修复费用进行加和。
代码片段和文件信息
#include
#include
#define inf 9999999
typedef struct
{
int city1city2coststatus;
}*HighwayHNode;
Highway H;
int nm*f*costmaxcost;
int cmp(const void *aconst void *b)
{
Highway A=(Highway)a; Highway B=(Highway)b;
if(A->status!=B->status)
return B->status-A->status;
else
return A->cost-B->cost;
}
void initial()
{
int i;
for(i=1;i<=n;i++)
f[i]=i;
}
int findfather(int x)
{
if(f[x]==x)
return x;
else return f[x]=findfather(f[x]);
}
void Union(int xint y)
{
int fx=findfather(x);
int fy=findfather(y);
if(fx==fy)
return ;
f[fx]=fy;
}
int main()
{
scanf(“%d%d“&n&m);
f=malloc(sizeof(int)*(n+1));
cost=malloc(sizeof(int)*(n+1));
H=malloc(sizeof(HNode)*m);
int i;
for(i=1;i<=n;i++)
{f[i]=i;cost[i]=0;}
for(i=0;i scanf(“%d%d%d%d“&H[i].city1&H[i].city2&H[i].cost&H[i].status);
qsort(Hmsizeof(HNode)cmp);
int jk;
//printf(“1\n“);
for(i=1maxcost=0;i<=n;i++) //if city_i is conquered
相关资源
- The Secret Path 3D 3D魔方迷宫[源码][scra
- Xpath生成器,自动生成可用的Xpath。
-
xm
l课件及例题(xm l) -
Differential ex
pression patterns of Toll-li - 希捷固件7200.9 TONKA15 S.71 3..ACH PATA.ra
- Anti-biofilm Activity of Resveratrol and Ursol
- Navicat Keygen Patch v5.6.0 DFoX
- Game Programming Patterns.pdf
- Microservice patterns
- dive into design patterns(Alexander Shvets)
- Investigation of the Lower Resistance Meridian
-
A web-ba
sed interview platform with geospat - Addison Wesley Refactoring To Patterns.pdf
- PatchNavicat11.0.10破解文件亲测可用
- A Pathfinding Project Pro v4.2.2.rar
- Characterization and Cytocompatibility of Nano
- patchedcode.bin
- IT十年经典书系列英文版-Design_Patter
- OzCode3.X Patch 注册机
- Bishop - Pattern Recognition And Machine Learn
- The evolution and origin of animal Toll-like r
- Pathon开发象棋小游戏总文件
- 计算机组成与设计:软硬件接口技术
- PathSim代码实现
- 《重构与模式》Refactoring to Patterns中文
- Visual SVN 4.0.2 Patch
- Molecular identification polymorphism and asso
- THE RAS/PI3K PATHWAY IS INVOLVED IN THE IMPAIR
- hands-on_design-patterns-delphi_pdf-code.rar
- unity寻路插件:A*Pathfinding
评论
共有 条评论