
树的直径
图论
Aloof__
笔记是记忆的缓冲
展开
-
Codeforces Round #668 (Div. 2) Balanced Bitstring&Tree Tag
C - Balanced Bitstring题意:给你一个二进制字符串s,里面可能会包含 “?" ;”?“可以修改成0或者1;现在给你一个k,问s的任意长度与为k的子串能否满足以下条件:长度为k的子串中0和1的数量相等,都是;思路:首先要发现一个规律 s[i]==s[i+k] ,以为只有这样才能满足上述条件;然后字符串s从位置k开始只要遇见”?“直接跳过,遇见不是”?“的要满足下面条件:若s[i%k]!="?",则s[i%k]!=s[i];如果等于那就不合法;如...原创 2020-09-13 14:04:41 · 204 阅读 · 0 评论 -
HDU 2196 -Computer【树形DP】(树的直径+动态规划)(dfs)(bfs)
一所学校不久前买了第一台电脑(所以这台电脑的ID是1)。近年来,学校购买了N-1新电脑。每台新电脑都连接到一台先前安装的电脑上。学校的管理人员担心网络运行缓慢,希望知道第i台计算机需要发送信号的最大距离si(即到最远计算机的电缆长度)。您需要提供此信息。提示:示例输入与此图对应。从图中,你可以看到计算机4离1最远,所以s1=3。计算机4和5是距离2最远的,所以s2=2。计算机5是离3最远的,所...原创 2019-07-25 18:11:20 · 468 阅读 · 0 评论 -
树的直径以及模板
模板:int dis[100020];int vist[100020];vector<pair<int,int> > v[100020];int m,n,ans;int bfs(int x){ memset(dis,0,sizeof dis); memset(vist,0,sizeof vist); queue<int> q;...原创 2019-08-09 17:34:05 · 217 阅读 · 0 评论 -
Labyrinth POJ - 1383 (树的直径模板)(dfs)(bfs)
The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them either filled by rock, or free. There is also a little hook ...原创 2019-08-31 15:21:00 · 219 阅读 · 0 评论 -
Cow Marathon POJ - 1985(树的直径模板)
After hearing about the epidemic of obesity in the USA, Farmer John wants his cows to get more exercise, so he has committed to create a bovine marathon for his cows to run. The marathon route will in...原创 2019-08-31 15:25:42 · 162 阅读 · 0 评论 -
Roads in the North POJ - 2631 (树的直径模板)(dfs)(bfs)
Building and maintaining roads among communities in the far North is an expensive business. With this in mind, the roads are build such that there is only one route from a village to a village that do...原创 2019-08-31 15:40:14 · 155 阅读 · 0 评论 -
Farthest Nodes in a Tree LightOJ - 1094 (树的直径模板)
Given a tree (a connected graph with no cycles), you have to find the farthest nodes in the tree. The edges of the tree are weighted and undirected. That means you have to find two nodes in the tree w...原创 2019-08-31 15:44:19 · 164 阅读 · 0 评论