摘要:http://poj.org/problem?id=2421无向图的最小生成树 Kruskal算法Constructing RoadsTime Limit:2000MSMemory Limit:65536KDescriptionThere are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if
阅读全文
摘要:http://poj.org/problem?id=2560本题跟其他题差不多,只不过节点的权重需要自己计算FrecklesTime Limit:1000MSMemory Limit:65536KDescriptionIn an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so
阅读全文
摘要:这题就是最小生成树,不过样例输出看了好久,一看DISCUSS才知道,这题是SPJ,答案不唯一,不必管样例下面Kruskal+并查集一次AC!!NetworkTime Limit:1000MSMemory Limit:30000KTotal Submissions:7721Accepted:2835Special JudgeDescriptionAndrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in th
阅读全文
摘要:这题的题意并不难,就是根据不同车型的代号分别求出两个代号的“距离”然后根据距离选择一个最小的生成树,下面用Kruskal算法实现,虽然AC了,资源占用很大,还需改进Truck HistoryTime Limit:2000MSMemory Limit:65536KDescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has
阅读全文
摘要:Agri-NetTime Limit:1000MSMemory Limit:10000KTotal Submissions:17635Accepted:7091DescriptionFarmer 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 needs your help, of course.Farmer John ordered a high speed connecti
阅读全文
摘要:Is It A Tree?Time Limit:1000MSMemory Limit:10000KTotal Submissions:9821Accepted:3354DescriptionA tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties.There is exac
阅读全文
摘要:食物链Time Limit:1000MSMemory Limit:10000KTotal Submissions:19801Accepted:5655Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句
阅读全文
摘要:POJ 1287NetworkingTime Limit:1000MSMemory Limit:10000KTotal Submissions:2924Accepted:1579DescriptionYou are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of p
阅读全文
摘要:#include<stdio.h>#defineMAX30000intf[MAX];//这里的1001只是一个示意性的数字代表初始状态下的分支数目intr[MAX];intflag;//由于不知道应该将子树挂到那个集合上面去,故需要一个准则,这里的准则是将子树挂到//r值大的集合上面去,初始状态下r数组的值均为一,代表每个分支下只有一个数字intfind(intn){if(f[n]==n)returnn;elsef[n]=find(f[n]);returnf[n];}//查找函数,并压缩路径intUnion(intx,inty){inta=find(x);intb=find(y);
阅读全文