图论
文章平均质量分 73
旺 崽
这个作者很懒,什么都没留下…
展开
-
LeetCode 5932 合法重新排列数对
题目链接给你一个下标从 0 开始的二维整数数组 pairs ,其中 pairs[i] = [starti, endi] 。如果 pairs 的一个重新排列,满足对每一个下标 i ( 1 <= i < pairs.length )都有 endi-1 == starti ,那么我们就认为这个重新排列是 pairs 的一个 合法重新排列 。请你返回 任意一个 pairs 的合法重新排列。注意:数据保证至少存在一个 pairs 的合法重新排列。示例 1:输入:pairs = [[5,1],[4原创 2021-12-05 18:36:11 · 307 阅读 · 0 评论 -
LeetCode 1319 连通网络的操作次数
LeetCode 1319 连通网络的操作次数题目链接用以太网线缆将 n 台计算机连接成一个网络,计算机的编号从 0 到 n-1。线缆用 connections 表示,其中 connections[i] = [a, b] 连接了计算机 a 和 b。网络中的任何一台计算机都可以通过网络直接或者间接访问同一个网络中其他任意一台计算机。给你这个计算机网络的初始布线 connections,你可以拔开任意两台直连计算机之间的线缆,并用它连接一对未直连的计算机。请你计算并返回使所有计算机都连通所需的最少操作次原创 2021-01-23 17:14:38 · 1847 阅读 · 0 评论 -
LeetCode 399 除法求值
LeetCode 399 除法求值题目链接给你一个变量对数组 equationsequationsequations 和一个实数值数组 valuesvaluesvalues 作为已知条件,其中 equations[i]=[Ai,Bi]equations[i] = [A_i, B_i]equations[i]=[Ai,Bi] 和 values[i]values[i]values[i] 共同表示等式 AiBi=values[i]\frac{A_i}{ B_i} = values[i]BiAi=va原创 2021-01-16 19:25:30 · 2383 阅读 · 0 评论 -
牛客编程巅峰赛S2第5场 - 钻石&王者 C.Tree III
牛客编程巅峰赛S2第5场 - 钻石&王者 C.Tree III题目链接题目描述给出一棵有n个节点的节点标号为1~n的有根树(根为第一个节点,并给出从第2个节点到第n个节点的父结点),请你求解它的“第二直径”的长度,即树上任意两点距离非严格的第二长距离为多少(也就是说,如果存在两条不同的,长度均为max的路径,则返回max)。树:一张有n个节点,n-1条边的无向连通图。示例1输入[1,2,3,4]返回值3示例2输入[1,1,1,1]返回值2图论定理,树的第二直径一原创 2020-12-01 22:16:48 · 2356 阅读 · 0 评论 -
2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program
2019 China Collegiate Programming Contest Qinhuangdao Onsite F. Forest Program题目链接The kingdom of Z is fighting against desertification these years since there are plenty of deserts in its wide and huge territory. The deserts are too arid to have rainfall原创 2020-10-03 17:07:45 · 2637 阅读 · 0 评论 -
2020牛客国庆集训派对day1 C.Bob in Wonderland
2020牛客国庆集训派对day1 C.Bob in Wonderland题目链接题目描述A chain, as everybody knows, is made of connected links. Typically, all links are of the same shape and size. Bob is a blacksmith apprentice, and he is making his own first iridium chain. He follows the tradit原创 2020-10-02 09:47:29 · 2581 阅读 · 0 评论 -
EOJ Monthly 2020.9 Sponsored by TuSimple B. 健康监测计划
EOJ Monthly 2020.9 Sponsored by TuSimple B. 健康监测计划题目链接规律题~对于 kkk 为偶数的时候,就是取 k2\frac{k}{2}2k 次叶子,当 kkk 为奇数的时候,多取一个结点,AC代码如下:#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e6+5;int n,k,u,v,ans=0,d[N],h[N];vecto原创 2020-09-27 16:49:02 · 2488 阅读 · 0 评论 -
牛客练习赛70 D.数树
牛客练习赛70 D.数树题目链接题意很简单,就是求大于 111 的连通块的数量,画几个图很容易发现连通块的数量就等于点的数量减边的数量,所以只需要实时记录点和边的数量即可,AC代码如下:#include <bits/stdc++.h>using namespace std;typedef long long ll;unordered_map<int,int>vis;map<pair<int,int>,int>m;int main() {原创 2020-09-26 16:31:34 · 2567 阅读 · 0 评论 -
2020牛客暑期多校训练营(第二场)C.Cover the Tree
2020牛客暑期多校训练营(第二场)C.Cover the Tree题目链接题目描述Given an unrooted tree, you should choose the minimum number of chains that all edges in the tree are covered by at least one chain. Print the minimum number and one solution. If there are multiple solutions, pr原创 2020-07-14 19:25:23 · 2509 阅读 · 0 评论 -
2019牛客暑期多校训练营(第二场)D.Kth Minimum Clique
2019牛客暑期多校训练营(第二场)D.Kth Minimum Clique题目链接题目描述Given a vertex-weighted graph with N vertices, find out the K-th minimum weighted clique.A subset of vertices of an undirected graph is called clique if and only if every two distinct vertices in the subset原创 2020-06-21 16:10:21 · 2321 阅读 · 0 评论 -
Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! D. Johnny and Contribution
Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! D. Johnny and ContributionToday Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs ha原创 2020-06-14 10:45:44 · 2392 阅读 · 0 评论 -
Codeforces Round #644 (Div. 3) E.Polygon
Codeforces Round #644 (Div. 3) E.Polygon题目链接Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0.On the polygon, military training was held. The soldiers placed a canno原创 2020-05-25 10:48:36 · 2325 阅读 · 0 评论 -
牛客小白月赛25 C.白魔法师
牛客小白月赛25 C.白魔法师题目链接题目描述你是一个白魔法师。现在你拿到了一棵树,树上有 个点,每个点被染成了黑色或白色。你可以释放一次魔法,将某个点染成白色。(该点不一定是黑色点,也可以是白色点)现在释放魔法后要保证最大的白色点连通块尽可能大。请求出最大白色连通块的大小。注:所谓白色连通块,指这颗树的某个连通子图,上面的点全部是白色。输入描述:第一行输入一个正整数 n ,代表树的顶点数量。第二行输入一个长度为 n 的、仅由’W’和’B’组成的字符串,第 i 个点为’W’代表该点为白原创 2020-05-20 16:04:49 · 2670 阅读 · 0 评论 -
AtCoder Beginner Contest 168 D... (Double Dots)
AtCoder Beginner Contest 168 D… (Double Dots)题目链接简单图论题,从 111 点 BFS 即可,用 ans[i]ans[i]ans[i] 记录答案,如果距离可以更新就把ans[i]ans[i]ans[i] 置为前一个点即可,注意 DFS 会超时,AC代码如下: #include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+5;vector&原创 2020-05-18 13:41:25 · 2331 阅读 · 0 评论 -
AtCoder Beginner Contest 163 F.path pass i
AtCoder Beginner Contest 163 F.path pass i题目链接一道比较有意思的树的问题,题意很简单就不赘述了~首先我们知道对一棵节点为 nnn 的树,总路径数 sumsumsum 一定为 n∗(n+1)/2n*(n+1)/2n∗(n+1)/2 ,可以自己画图验证,这是离散数学的基本知识~如果对每个点都遍历一遍显然不现实,所以我们就以 1 为根节点进行 DFS...原创 2020-04-20 16:40:15 · 2625 阅读 · 4 评论 -
Codeforces Round #635 (Div. 2) C.Linova and Kingdom
Codeforces Round #635 (Div. 2) C.Linova and KingdomWriting light novels is the most important thing in Linova’s life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light ...原创 2020-04-16 10:55:40 · 2398 阅读 · 0 评论 -
AtCoder Beginner Contest 160 D.Line++
AtCoder Beginner Contest 160 D.Line++题目链接Problem StatementWe have an undirected graph G with N vertices numbered 1 to N and N edges as follows:For each i=1,2,…,N−1, there is an edge between Vertex...原创 2020-03-29 10:10:18 · 2383 阅读 · 0 评论 -
Codeforces round #628 C.Ehab and Path-etic MEXs
Codeforces round #628 C.Ehab and Path-etic MEXsYou are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold:Every label is an...原创 2020-03-16 08:29:46 · 2497 阅读 · 0 评论 -
牛客挑战赛35 B.线图
牛客挑战赛35 B.线图题目描述牛客题目太难搞了,我就不复制了,这里就是求一个图无穷大的线图的顶点数,线图定义请自查ZJOI 线图(若顶点数发散输出-1)输入描述:第一行数字n,m表示点数和边数接下来m行,每行2个数字u,v,表示一条边输出描述:示例1输入4 51 22 31 33 41 4输出-1示例2输入3 31 22 31 3输出3...原创 2019-12-21 10:37:38 · 2717 阅读 · 0 评论 -
PAT甲级 1020 Tree Traversals
PAT甲级 1020 Tree TraversalsSuppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order tr...原创 2020-02-12 22:00:25 · 2592 阅读 · 0 评论 -
PAT甲级 1004 Counting Leaves
PAT甲级 1004 Counting LeavesA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one te...原创 2020-01-30 17:03:58 · 2561 阅读 · 0 评论 -
HHUOJ 1698 哈夫曼树
HHUOJ 1698 哈夫曼树题目描述哈夫曼树,第一行输入一个数n,表示叶结点的个数。需要用这些叶结点生成哈夫曼树,根据哈夫曼树的概念,这些结点有权值,即weight,题目需要输出所有结点的值与权值的乘积之和。输入输入有多组数据。每组第一行输入一个数n,接着输入n个叶节点(叶节点权值不超过100,2<=n<=1000)。输出输出权值。样例输入22 8 35 11...原创 2019-08-31 17:13:40 · 3030 阅读 · 0 评论 -
HHUOJ 1662 算法10-10,10-11:堆排序
HHUOJ 1662 算法10-10,10-11:堆排序题目描述堆排序是一种利用堆结构进行排序的方法,它只需要一个记录大小的辅助空间,每个待排序的记录仅需要占用一个存储空间。首先建立小根堆或大根堆,然后通过利用堆的性质即堆顶的元素是最小或最大值,从而依次得出每一个元素的位置。堆排序的算法可以描述如下:在本题中,读入一串整数,将其使用以上描述的堆排序的方法从小到大排序,并输出。输入输入...原创 2019-08-31 16:46:57 · 3050 阅读 · 0 评论 -
HHUOJ 1758 Problem D
HHUOJ 1758 Problem D题目描述已知某二叉树的先序序列和中序序列,编程计算并输出该二叉树的后序序列。输入有多组数据,每组分为两行输入,第一行表示指定二叉树的先序序列,第二行表示该二叉树的中序序列,序列元素均为大写英文字符,表示二叉树的结点。输出对于每组数组,在一行上输出该二叉树的后序序列。样例输入ABDGCEFHDGBAECHF样例输出GDBEHFCA模...原创 2019-08-29 11:47:04 · 3066 阅读 · 0 评论 -
PAT甲级 1021 Deepest Root
PAT甲级 1021 Deepest RootA graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a hi...原创 2020-02-14 15:06:31 · 2602 阅读 · 0 评论