图论
文章平均质量分 52
Wss0130
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HDU1863畅通工程
这是我第一次接触图论。。。 这个题不难,是并查集和Kruskal算法的应用 就是先对边进行排序,判断两个点的关系。。。 #include #include #define MAX 9999999 int i,k,f1,f2,m,n,sum; int father[101]; struct NODE{ int u; // 起点 int v; // 终点 in原创 2012-08-15 11:06:26 · 483 阅读 · 0 评论 -
题目1450:产生冠军
// 判断是不是只有1个入度为0的结点 // 关键是判断选手的编号 #include #include struct Node{ char name[100]; // 选手名字 int indegree; // 该选手的入度 }edge[1001]; int main() { int n; wh原创 2014-03-14 10:18:13 · 1048 阅读 · 0 评论 -
题目1449:确定比赛名次
#include #include #include using namespace std; vector edge[501]; priority_queue,greater > Q; // 小顶堆 int main() { int inDegree[501]; int n,m; while(scanf("%d%d",&n,&m)!=EOF){原创 2014-03-13 21:11:49 · 1042 阅读 · 0 评论 -
题目1448:Legal or Not
// 用拓扑排序判断是否是有向无环图。。。 #include #include #include using namespace std; vector edge[501]; // 邻接链表,只保存与其相邻的结点编号 queue Q; // 保存入度为0的结点的队列 int main() { int inDegree[501];原创 2014-03-13 20:00:09 · 588 阅读 · 0 评论 -
题目1447:最短路
// 弗洛伊德算法:求两点间的最短路径 #include int ans[101][101]; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF){ if(n==0 && m==0) break; for(int i=1;i for(int j=1;j原创 2014-03-13 12:13:06 · 813 阅读 · 0 评论 -
题目1008:最短路径问题
// 迪杰斯特拉算法 #include #include using namespace std; struct E{ int next; int c; int cost; }; vector edge[1001]; int Dis[1001]; int cost[1001]; bool mark[1001]; int main() {原创 2014-03-13 17:17:51 · 1304 阅读 · 0 评论 -
题目1445:How Many Tables
// 并查集,求有多少个集合,即根结点个数。。。 #include #define N 1000 int Tree[N]; int findRoot(int x){ if(Tree[x]==-1) return x; else{ int tmp=findRoot(Tree[x]); Tree[x]=tmp; retu原创 2014-03-12 10:41:31 · 504 阅读 · 0 评论 -
题目1017:还是畅通工程
// 克鲁斯卡尔算法,对边的权值从小到大排序 #include #include using namespace std; #define N 101 int Tree[N]; int findRoot(int x){ // 查找该结点的根结点 if(Tree[x]==-1) return x; else{ int tmp原创 2014-03-12 17:52:10 · 863 阅读 · 0 评论 -
题目1024:畅通工程
// 最小生成树,多了判断是否存在最小生成树这一步。。。 #include #include using namespace std; #define N 200 int Tree[N]; int sum[N]; struct Edge{ // 边结构体 int a,b; int cost; bool operator原创 2014-03-12 17:50:16 · 921 阅读 · 0 评论 -
题目1144:Freckles
// 实际还是求最小生成树 #include #include #include using namespace std; #define N 101 int Tree[N]; int findRoot(int x){ // 查找根结点 if(Tree[x]==-1) return x; else{ int t原创 2014-03-12 17:18:57 · 798 阅读 · 0 评论 -
题目1028:继续畅通工程
// 若道路已修建,则费用为0 ,剩下的就是查找最小生成树的问题。。。 #include #include using namespace std; #define N 1000 struct Edge{ // 边结构体 int a,b; // 边的两个顶点 int cost; // 权值 int f; // 道路修建状态,0表示未修建原创 2014-03-12 18:29:25 · 1752 阅读 · 0 评论 -
题目1444:More is better
// 求并查集中集合中元素的个数。。。 #include #define N 10000001 int Tree[N]; int sum[N]; // 以结点i为根的树的结点个数,仅当Tree[i]=-1时有效 int findRoot(int x){ // 查找结点x所在树的根结点,并查集 if(Tree[x]==-1) return原创 2014-03-12 09:59:16 · 565 阅读 · 0 评论 -
题目1154:Jungle Roads
// 最小生成树。。。 #include #include using namespace std; #define N 101 int Tree[N]; int findRoot(int x){ if(Tree[x]==-1) return x; else{ int tmp=findRoot(Tree[x]); Tree[原创 2014-03-12 17:20:28 · 674 阅读 · 0 评论 -
题目1109:连通图
// 判断最大集合里的结点个数是否等于n,若等于,则是连通图;否则,则不是连通图 // 最终还是考察并查集 #include #define N 1000 int Tree[N]; int sum[N]; int findRoot(int x){ if(Tree[x]==-1) return x; else{ int tmp=findRoot(Tr原创 2014-03-12 10:26:12 · 605 阅读 · 0 评论 -
题目1012:畅通工程
// 考察并查集。。。 #include int Tree[100]; int findRoot(int x){ // 查找某个结点所在树的根节点,并查集 if(Tree[x]==-1) return x; else { int tmp=findRoot(Tree[x]原创 2014-03-12 09:34:56 · 860 阅读 · 0 评论 -
题目1545:奇怪的连通图
// 先对边排序然后贪心、用并查集建最小生成树、然后判断1和N是否连通 #include #include #include using namespace std; #define N 10001 struct E{ // 边结构体 int a,b; // 两个结点编号 int cost; // 边权值 bool原创 2014-03-15 22:12:26 · 560 阅读 · 0 评论
分享