![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论
图论题解
LZH0217
这个作者很懒,什么都没留下…
展开
-
2020 China Collegiate Programming Contest Qinhuangdao Site-重现赛 7-6 Friendly Group(Tarjan 或 并查集)
7-6 Friendly Group题目Sample Input24 51 21 31 42 33 42 11 2Sample OutputCase #1: 1Case #2: 0分析把他们之间的好朋友关系对应到图上,两个人是好朋友的话,他们之间连一条边,显然环是要满足的最低要求,在一个环中,点和边个数一样,对答案的贡献是0,如果不是环,那么点的个数大于边数,那么对答案的贡献是负的。最后就是要对无向图强联通分量缩点,记下每个强联通分量中的点的个数和边的个数。code原创 2020-10-20 18:24:03 · 730 阅读 · 0 评论 -
P3387 【模板】缩点(Tarjan缩点,拓扑序上dp)模板
P3387 【模板】缩点题目链接#include <iostream>#include <algorithm>#include <vector>#include <cstdio>#include <stack>#include <queue>#define sc(x) scanf("%d", &(x))#define sca(x, y) scanf("%d%d", &(x), &(y))#d原创 2020-09-25 16:03:51 · 157 阅读 · 0 评论 -
Til the Cows Come Home POJ - 2387(Dijkstra模板 优先队列优化)
Til the Cows Come HomePOJ - 2387#include <cstdio>#include <vector>#include <queue>#include <cstring>using namespace std;typedef pair<int, int> pii;const int INF = 0x3f3f3f3f;const int N = 1000 + 5;struct node {原创 2020-09-23 21:33:07 · 121 阅读 · 0 评论 -
P3385 【模板】负环 (spfa模板,判断负环)
P3385 【模板】负环题目链接code#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <string>#include <vector>#include <stack>#include <queue>using namespace std;const int N = 3原创 2020-09-17 19:39:48 · 96 阅读 · 0 评论 -
LeetCode 207.课程表(拓扑排序)
solutionbfs实现。注意题目中的边缘列表要转换成邻接表。codeclass Solution {private: vector<vector<int>> edge; vector<int> indeg;public: bool canFinish(int numCourses, vector<vector<int>>& prerequisites) { edge.resize(nu.原创 2020-08-04 09:54:57 · 114 阅读 · 0 评论 -
智算之道初赛第三场 - 高校组 题解
1. 水杯签到题code#include <cstdio>using namespace std;typedef long long ll;int main(){#ifdef LZH_LOCAL freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout);#endif int n, L, A, B; scanf("%d%d%d%d", &n, &L, &原创 2020-07-28 13:06:06 · 251 阅读 · 0 评论 -
华华和月月逛公园(Tarjan求割边)
华华和月月逛公园题目链接题目描述月月和华华一起去逛公园了。公园很大,为了方便,可以抽象的看成一个N个点M条边的无向连通图(点是景点,边是道路)。公园唯一的入口在1号点,月月和华华要从这里出发,并打算参观所有的景点。因为他们感情很好,走多远都不会觉得无聊,所以所有景点和道路都可以无数次的重复经过。月月发现,有些路可走可不走,有些路则必须要走,否则就无法参观所有的景点。现在月月想知道,有几条路是不一定要经过的。因为这是个很正常的公园,所以没有重边和自环。输入描述:第一行两个正整数N和M,表示点数和边数原创 2020-05-23 17:31:50 · 151 阅读 · 0 评论 -
无向图的割点割边和双连通分量
无向图的割点、割边Tarjan算法求无向图的割点//啊哈算法 图的割点#include <cstdio>#include <algorithm>#include <cstring>using namespace std;typedef long long ll;const int N = 2e4 + 10;int n, m, root;b...原创 2019-11-08 21:07:50 · 473 阅读 · 0 评论 -
牛妹的游戏 - 牛客练习赛62(拉姆塞理论 图)
牛妹的游戏https://ac.nowcoder.com/acm/contest/5205/A拉姆塞(Ramsey)理论拉姆塞理论可以用通常的语言来表述。在一个集会上,两个人或者彼此认识,或者彼此不认识,拉姆塞得出结果是说,当集会人数大于或等于6时,则必定有3个人,他们或者彼此认识或者彼此都不认识。题意:一个无向图,给 nnn 个点,mmm 条边,看这个图或者它的补图是否可以有一个长...原创 2020-04-26 00:44:28 · 206 阅读 · 0 评论 -
Shortest Path(4月3日题目 DFS 树)
Shortest Pathhttps://ac.nowcoder.com/acm/problem/13886https://ac.nowcoder.com/discuss/398540题意:给你一棵有 nnn 个点的树(nnn 是偶数),你需要将 nnn 个点分为 n/2n/2n/2 个点对,使得每个点对的两点间的距离和最小。思路:边不能重复选,如果选了重复的边,那么肯定可以找到一种距...原创 2020-04-07 19:06:16 · 156 阅读 · 0 评论 -
牛客小白月赛23 G 树上求和(图、树)
G 树上求和https://ac.nowcoder.com/acm/contest/4784/G题解:计算每条边在答案中被加了多少次,然后把这个次数升序排序,从前往后依次分配权值 n−1,n−2,n−3,…,3,2,1n-1,n-2,n-3,\dots,3,2,1n−1,n−2,n−3,…,3,2,1。计算方法,首先dfs计算出每个结点的子树的结点个数(包括此结点),然后 (n−i)∗s...原创 2020-03-24 23:15:32 · 175 阅读 · 0 评论 -
UCF Local Programming Contest 2015 I. Longest Path(竞赛图 求哈密顿路径)
$任意两个点之间有且仅一条有向边,这是一个竞赛图。竞赛图一定存在哈密顿路径。Longest PathYou are visiting a lovely garden, with several points of interest. Every pair of points of interest have a single, one way path (edge) connect...原创 2020-03-15 09:49:09 · 237 阅读 · 0 评论 -
PTA L2-2 冰岛人 (25分)
PTAL2-2冰岛人(25分)2018年世界杯,冰岛队因1:1平了强大的阿根廷队而一战成名。好事者发现冰岛人的名字后面似乎都有个“松”(son),于是有网友科普如下:冰岛人沿用的是维京人古老的父系姓制,孩子的姓等于父亲的名加后缀,如果是儿子就加 sson,女儿则加 sdottir。因为冰岛人口较少,为避免近亲繁衍,本地人交往前先用个 App 查一下两人祖宗若干代有无联系。本题就请...原创 2020-03-10 22:03:21 · 1224 阅读 · 0 评论 -
【Trie树+并查集+欧拉图】Colored Sticks (POJ - 2513)
Colored Sticks POJ - 2513DescriptionYou are given a bunch of wooden sticks. Each endpoint of each stick is colored with some color. Is it possible to align the sticks in a straight line such that th...原创 2019-11-14 16:42:00 · 159 阅读 · 0 评论 -
【强连通分量缩点】Popular Cows POJ - 2186
Popular Cows - Tarjan强连通分量缩点DescriptionEvery cow’s dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) o...原创 2019-11-12 15:20:36 · 167 阅读 · 3 评论 -
【拓扑排序】Sorting It All Out POJ - 1094
拓扑排序An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C,...原创 2019-11-11 21:20:24 · 131 阅读 · 0 评论 -
【拓扑排序+bitset】可达性统计
/*可达性统计时间限制: 1 Sec 内存限制: 128 MB题目描述给定一张N个点M条边的有向无环图,分别统计从每个点出发能够到达的点的数量。N,M≤30000。输入第一行两个整数N,M,接下来M行每行两个整数x,y,表示从x到y的一条有向边。输出共N行,表示每个点能够到达的点的数量。样例输入复制样例数据10 103 82 32 55 95 92 3...原创 2019-09-08 16:43:58 · 104 阅读 · 0 评论 -
【拓扑排序】Topological Sort Aizu - GRL_4_B
Topological SortAizu - GRL_4_BA directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before anothe...原创 2019-09-04 17:07:41 · 163 阅读 · 0 评论 -
【最小割的唯一性判定】ZOJ2587 Unique Attack
最小割的唯一性判定ZOJ2587 Unique Attack题意给定一个无向图, N 个点 M 条边,要求判断两个点A 和 B 之间的最小割是否唯一。思路建立网络流模型,求出最大流后,在残余网络分别从 源点S 和 汇点T 开始沿着未饱和的边进行搜索,如果搜到的总的顶点的个数等于N,则说明最小割唯一,否则最小割不唯一。我用的vector邻接表存的图,Dinic求的最大流...原创 2019-08-15 14:40:52 · 444 阅读 · 0 评论