ZOJ 3204 Connect them(字典序输出)】的更多相关文章

主要就是将最小生成树的边按字典序输出. 读取数据时,把较小的端点赋给u,较大的端点号赋值给v. 这里要用两次排序,写两个比较器: 第一次是将所有边从小到大排序,边权相同时按u从小到大,u相同时按v从小到大,用kruskal求出最小生成树. 第二次将求出的最小生成树的边在排序,这次只要按u.v从小到大排序即可. #include <algorithm> #include <cstring> #include <cstdio> using namespace std; in…
Connect them ZOJ - 3204 You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers i and j is the same as connecting computers j and i). T…
这道题目麻烦在输出的时候需要按照字典序输出,不过写了 Compare 函数还是比较简单的 因为是裸的 Kruscal ,所以就直接上代码了- Source Code : //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3367 题目大意: 让你求最小生成树,并且按照字典序输出哪些点连接.无解输出-1 这里的字典序定义为:(不翻译啦~,详见我的比较函数) A solution A is a line of p integers: a1, a2, ...ap. Another solution B different from A is a line of q integers: b1, b2,…
Connect them Time Limit: 1 Second      Memory Limit: 32768 KB You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers iand j is the sam…
题意:裸最小生成树,主要是要按照字典序. 思路:模板 prim: #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define INF 0x7fffffff #define MAXN 128 bool vis[MAXN]; int lowu[MAXN];//记录起始边(已加入集合中的边) int lowc[MAX…
最小生成树,我用的是并查集+贪心的写法. #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; ; int c[maxn][maxn]; int father[maxn]; int flag[maxn]; struct abc{ int fei, a, b; }dt[maxn*maxn]; struct ans{ int a…
John's trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8641   Accepted: 2893   Special Judge Description Little Johnny has got a new car. He decided to drive around the town to visit his friends. Johnny wanted to visit all his frien…
The order of a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2070 Accepted Submission(s): 1097 Problem Description As we know,the shape of a binary search tree is greatly related to the ord…
题目:http://poj.org/problem?id=1041 明明是欧拉回路字典序输出的模板. 优先队列存边有毒.写跪.学习学习TJ发现只要按边权从大到小排序连边就能正常用邻接表了! 还有一种存边的方法是把边的标号放到数组第二维里,达到一个桶的效果. 我当然知道那种模板是先dfs再在return的时候把边加进栈里最后倒序输出,可是这题为什么不正序呢? 然后WA了.发现可能先把一个点的度走完但此时其他点还有度这样的. 于是有了flag和return.然后就超时了. 再看看TJ,突然就明白了为…