Teen Girl Squad Description: You are part of a group of n teenage girls armed with cellphones. You have some news you want to tell everyone in the group. The problem is that no two of you are in the same room, and you must communicate using only cell…
Problem ITeen Girl Squad Input: Standard Input Output: Standard Output You are part of a group of n teenage girls armed with cellphones. You have some news you want to tell everyone in the group. The problem is that no two of you are in the same room…
最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <stack> #include <queue> #include <cmath> #include <vector> us…
题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: 最小树形图模板题. 朱刘算法,复杂度O(n^3),n的规模较小. 代码: #include <stdio.h> #include <string.h> #include <vector> using namespace std; ; const int inf = 0x3…
Teen Girl Squad  Input: Standard Input Output: Standard Output You are part of a group of n teenage girls armed with cellphones. You have some news you want to tell everyone in the group. The problem is that no two of you are in the same room, and yo…
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 6126    Accepted Submission(s): 2181 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4009 Description: XiaoA lives in a village. Las…
题目链接:https://vjudge.net/problem/UVA-11183 You are part of a group of n teenage girls armed with cellphones. You have some news you want to tell everyone in the group. The problem is that no two of you are in the same room, and you must communicate us…
Problem I Teen Girl Squad  Input: Standard Input Output: Standard Output -- 3 spring rolls please. -- MSG'D!! -- Oh! My stomach lining! Strong Bad You are part of a group of n teenage girls armed with cellphones. You have some news you want to tell e…
[题意] 输入三元组(X,Y,C),有向图,定根0,输出MDST. InputThe first line of input gives the number of cases, N (N < 150). N test cases follow. Each one startswith two lines containing n (0 ≤ n ≤ 1000) and m (0 ≤ m ≤ 40, 000). Girls are numbered from 0 ton-1, and you ar…
解析: 裸的有向图最小生成树 代码 #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<sstream> #include<algorithm> #include<utility> #include<vector> #include<set> #include<map> #incl…
Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 20766   Accepted: 5920 题目链接:http://poj.org/problem?id=3164 Description: After a long lasting war on words, a war on arms finally breaks out between littleken’s and KnuthOce…
题意: 要使n个点之间能够互通,要使两点直接互通需要耗费它们之间的欧几里得距离的平方大小的花费,这说明每两个点都可以使其互通.接着有q个套餐可以选,一旦选了这些套餐,他们所包含的点自动就连起来了,所需要做的就是连上还未通的即可,q<=8.可以多买.求最小生成树所需的代价. 思路: 与普通求MST不同的就是多了套餐,而且还可以多买.每个套餐有买或不买两种可能,那么有28种可能,即256种. 如果不买套餐,至少需要求1次MST是确定的,这个复杂度已经是O(n*n)了.还得考虑哪些餐套可以搭配来买更便…
Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us.There is a large number of magnetic p…
题目大意:给一张无向图,求出最小树形图. 题目分析:套朱-刘算法模板就行了... 代码如下: # include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std; # define LL long long # define REP(i,s,n) for(int i=s;i<n;++i) # define CL(a,b) me…
题意:给一个N(N<=100)个点的联通图(无自环和平行边),求苗条度(最大边-最小边的值)尽量小的生成树. 解法:枚举+Kruskal.先从小到大排序边,枚举选择的最小的边. 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<algorithm> 5 #include<iostream> 6 using namespace std; 7 const…
第一个部分 前4题 次小生成树 算法:首先如果生成了最小生成树,那么这些树上的所有的边都进行标记.标记为树边. 接下来进行枚举,枚举任意一条不在MST上的边,如果加入这条边,那么肯定会在这棵树上形成一个环,如果还要维护处树的特点 那么就要在这个环上删去一条边,这样他还是树,删掉的边显然是这条链上权值最大边更可能形成次小生成树.那么就有2中方法可以做. 第一种PRIM在prim时候直接可以做出这个从I到J的链上权值最大的值MAX[i][j]; 同时可以用kruskal同样方式标记树边,然后DFS跑…
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //2019.3.18 POJ 2251 Dungeon Master POJ 3278 Catch That Cow  //4.8 POJ 3279 Fliptile POJ 1426 Find The Multiple  //4.8 POJ 3126 Prime Path POJ 3087 Shuffle…
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find The MultiplePOJ 3126 Prime PathPOJ 3087 Shuffle'm UpPOJ 3414 PotsFZU 2150 Fire GameUVA 11624 Fire!POJ 3984 迷宫问题HDU 1241 Oil Deposit…
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find The MultiplePOJ 3126 Prime PathPOJ 3087 Shuffle'm UpPOJ 3414 PotsFZU 2150 Fire GameUVA 11624 Fire!POJ 3984 迷宫问题HDU 1241 Oil DepositsHDU 1495 非常可乐HDU 26…
layout: post title: 训练指南 UVA- 11865(有向最小生成树 + 朱刘算法 + 二分) author: "luowentaoaa" catalog: true mathjax: true tags: - 最小生成树 - 图论 - 训练指南 Stream My Contest UVA - 11865 二分带宽,然后判断最小生成树是否小于cost值. #include<bits/stdc++.h> using namespace std; typede…
layout: post title: 训练指南 UVA - 11478(最短路BellmanFord+ 二分+ 差分约束) author: "luowentaoaa" catalog: true mathjax: true tags: - 最短路 - BellmanFord - 图论 - 训练指南 - 差分约束 Halum UVA - 11478 题意 带权有向图,每个点都可以有如下操作:令从ta出发的每一条边增加d,终止于ta的每一条边减小d 最后让所有边权的最小值非负且尽量大 题…
树的定义:连通无回路的无向图是一棵树. 有关树的问题: 1.最小生成树. 2.次小生成树. 3.有向图的最小树形图. 4.LCA(树上两点的最近公共祖先). 5.树的最小支配集.最小点覆盖.最大独立集. 一.最小生成树 解决的问题是:求无向图中边权值之和最小的生成树. 算法有Kruskal和Prim. Kruskal使用前向星和并查集实现,可以存储重边(平行边),时间复杂度是O(m log m  +  m),m是边的数量. Prim使用邻接矩阵建图,不可以存储重边(平行边),如果出现重边,存储的…
加权图相关算法 前言 本文主要介绍加权图算法中两个重要应用:最小生成树和最短路径. 求最小生成树时针对的是加权无向图,加权有向图的最小生成树算法成为"最小属树形图"问题,较为复杂,本文不做讨论. 求最短路径则是针对加权有向图,在不同限制条件下,适应不同的算法: 1. 权重非负,采用Dijkstra算法: 2. 不存在环,采用基于拓扑排序的最短路径算法,能够线性空间内解决问题: 3. 不存在负权重环,即如果存在环,环的各条边权重总和不能为负值,采用Bellman-Ford算法. 加权无向…
模版题为[poj 1287]Networking. 题意我就不说了,我就想简单讲一下Kruskal和Prim算法.卡Kruskal的题似乎几乎为0.(●-`o´-)ノ 假设有一个N个点的连通图,有M条边(不定向),求MST(Minimal Spanning Tree)最小生成树的值. 1.Kruskal 克鲁斯卡算法 概述:将边从小到大排序,依次将边两端的不在同一个联通分量/联盟的点分别加入一个个联盟内,将边也纳入,计入答案.最终N个点合并为一个联盟,也就是纳入联盟内的边达到N-1条就结束算法.…
最小树形图求的是有向图的最小生成树,跟无向图求最小生成树有很大的区别. 步骤大致如下: 1.求除了根节点以外每个节点的最小入边,记录前驱 2.判断除了根节点,是否每个节点都有入边,如果存在没有入边的点,说明树形图不存在,退出. 3.沿着节点的前驱找,如果发现环,把环缩点. 4.如果不存在环,结束.否则,跳到1. 其实我是来贴模板的... 比较好的讲解:最小树型图的求解与实现 代码讲解比较好的:hdu4009 Transfer water ( 最小树形图的模板 ) 用IO优化时死活TLE,改了sc…
题目1: SPOJ 2832 题目大意: 求一个矩阵行列式模一个数P后的值.p不一定是质数. 算法讨论: 因为有除法而且p不一定是质数,不一定有逆元,所以我们用辗转相除法. #include <cstdio> #include <iostream> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; ; typedef long long…
/*调了一下午的最小树形图,昨天刚刚看懂模板..最小树形图,就是有向图的最小生成树,很神奇==*/ #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define MAXN 1002 #define INF 0x3f3f3f3f using namespace std; struct Node{ int x,y,z; }nodes[MAXN]; struct Edge…
题目大意:给定一个有向图,根节点已知,求该有向图的最小树形图.最小树形图即有向图的最小生成树,定义为:选择一些边,使得根节点能够到达图中所有的节点,并使得选出的边的边权和最小. 题目算法:朱-刘算法(即由中国人朱永津和刘振宏共同发明的算法). 算法步骤如下: 1.判断图的连通性,若不连通直接无解,否则一定有解. 2.为除了根节点以外的所有点选择一个权值最小的入边,假设用pre数组记录前驱,f数组记录选择的边长,记所选边权和为temp. 3.(可利用并查集)判断选择的的边是否构成环,若没有则直接a…
题目链接:http://poj.org/problem?id=3164 详细可以看这里:http://www.cnblogs.com/vongang/archive/2012/07/18/2596851.html 我没怎么看懂 = =,姑且做个模板了.. 题意就是给n个点,m条单向边,并且已知根节点,求有向图的最小生成树. #include <stdio.h> #include <iostream> #include <string.h> #include <al…
题目链接:http://poj.org/problem?id=3164 题意:第一行为n, m,接下来n行为n个点的二维坐标, 再接下来m行每行输入两个数u, v,表点u到点v是单向可达的,求这个有向图的最小生成树即求最小树形图: 思路: 这是一道最小树形图模板题: 我们可以用朱刘算法来解: 朱刘算法只有3步,然后不断循环. 1:找到每个点的最小入边.既然是生成树,那么对于每个点来说,只要选一个权值最小的入边就可以了. 贪心思想.因为如果不是最小入边,那么它肯定不是最小树形图的一条边,考虑它是没…