这个时间短 700多s #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; struct node{ int u; int v; int w; }que[100000]; int father[505]; bool cmp(struct node a,struct node b){ return a.w<b.w;…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3371 Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10313    Accepted Submission(s): 2937 Problem Description In 2100, since th…
Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16070    Accepted Submission(s): 4177 Problem Description In 2100, since the sea level rise, most of the cities disappear. Thou…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64912   Accepted: 26854 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将所有点按照 \(a_{i,j}\) 按权值大小从小到大排序并依次插入这些点,我们实时维护一个 \(n\times n\) 的 bool 数组 \(vis\),\(vis_{i,j}\) 表示第 \(i\) 行第 \(j\) 列的数是否被访问了.当我们插入某个 \(a_{i,j}\) 时,如果 \(\…
一直以来只会Kruskal prim和dijkstra很像 只不过prim维护的是最短的边,而dijkstra维护的是最短的从起点到一个点的路径 同时prim要注意当前拓展的边是没有拓展过的 可以用堆优化 #include<bits/stdc++.h> #define REP(i, a, b) for(register int i = (a); i < (b); i++) #define _for(i, a, b) for(register int i = (a); i <= (b…
Kruscal算法求图的最小生成树 概述   和Prim算法求图的最小生成树一样,Kruscal算法求最小生成树也用到了贪心的思想,只不过前者是贪心地选择点,后者是贪心地选择边.而且在算法的实现中,我们还用用到了并查集(也称不相交集的)Union /Find 算法来判断两个节点连通后会不会形成一个环.该算法的思想很简单:将图的所有边按从小到大顺序排序,每次都选取权值最小的边加入最小生成树,如果该边的加入会使生成树形成一个环,则跳过该边.   这里引入并查集的概念,可以使问题变得简单化.并查集就是…
1009: 一带一路 时间限制: 1 Sec  内存限制: 128 MB 题目描述 一带一路是去去年习大大提出来的建设“新丝绸之路经济带”和“21世纪海上丝绸之路”的战略构想.其中就包括我们新疆乌鲁木齐,所以这也是对新疆来说是一个巨大的机遇.我们新疆要加强和周边国家的经济文化交流,就必然要和周边国家城市修许多路.现在假设有N座城市,每一个城市都有一个投资指标数,例如A城市和B城市的投资指标数分别为Ia和Ib,如果Ia或Ib或Ia-Ib的绝对值为素数或者为1,则A城市和B城市可以修路,否则不能.他…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3371 Problem Description In 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The governmen…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3371 984ms风险飘过~~~ /************************************************************************/ /* hdu Connect the Cities 最小生成树 题目大意:最小生成树,题目很长,题意很简单就是最小生成树.关键是构建图 */ /****************************************…