资源简介
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
相关资源
- Vax_Patch_1856.rar
- zw_jueqingnikong-10336909-PSOeconomic-dispatch
- 天眼查爬虫亲测可以用
- OS作业,c实现path,cd,pwd,history,执
- PAT甲级练习题155道分类xmind
- 2020PAT春季甲级 题目及AC代码
- 2019冬季甲级.zip
- UniPatcher_v2017.6及以下可用.zip
- Springer 会议用LaTeX tempate
- appcompat-v7
- 火狐浏览器firepath 0.9.7.1
- UniversalTermsrvPatch-x64
- AMD 补丁签名 ATIKMDAG-PATCHER
- Z.Dapper.Plus-cleaned-patched.zip
- TeamViewer_12.x_Patch_URET_v4.9.exe
- iar 8.50 patcher
- NS2 nist wimax patch
- Pattern Classification 2nd edition出版前版本
- compat-libcwait-2.1-1.i386.rpm
- flexlm.ecc.generic.patcher
- 873971781Mir2MapPath.rar
- IAR for ARM 8506修复工具
- 算法笔记.胡凡pdf
- PatchIDM.rar
- PatchNavicat.exe
- unity2018破解,unipatcher2018.7z
- ManageEngine_Patch_Manager_Plus_64bitStandardE
- 论文研究 - 基于Xlpat平台的美国高校药
- H3C Secpath1000f系列防火墙产品规格
- H3C SecPath高端防火墙NAT典型配置举例
评论
共有 条评论