当前位置: 首页 > news >正文

创新的江苏网站建设学院网站建设目的

创新的江苏网站建设,学院网站建设目的,c mvc 网站开发进阶之路,网络推广软件排行文章目录题目描述样例分析#xff1a;题意#xff1a;题解#xff1a;代码#xff1a;本题目传送题目树学是这个题的简易版#xff0c;也涉及换根问题#xff0c;可以先看看这个 树学 时间限制#xff1a;C/C 1秒#xff0c;其他语言2秒 空间限制#xff1a;C/C 32768… 文章目录题目描述样例分析题意题解代码本题目传送题目树学是这个题的简易版也涉及换根问题可以先看看这个 树学 时间限制C/C 1秒其他语言2秒 空间限制C/C 32768K其他语言65536K 64bit IO Format:%lld 题目描述 Trees are an important component of the natural landscape because of their prevention of erosion and the provision of a specific ather-sheltered ecosystem in and under their foliage. Trees have also been found to play an important role in producing oxygen and reducing carbon dioxide in the atmosphere, as well as moderating ground temperatures. They are also significant elements in landscaping and agriculture, both for their aesthetic appeal and their orchard crops (such as apples). Wood from trees is a common building material. Trees also play an intimate role in many of the world’s mythologies. Many scholars are interested in finding peculiar properties about trees, such as the center of a tree, tree counting, tree coloring. A(x) is one of such properties. A(x) (accumulation degree of node x) is defined as follows: Each edge of the tree has an positive capacity.The nodes with degree of one in the tree are named terminals.The flow of each edge can’t exceed its capacity.A(x) is the maximal flow that node x can flow to other terminal nodes. Since it may be hard to understand the definition, an example is showed below: 样例分析 A(1)115824 Details: 1-2 11 1-4-3 5 1-4-5 8(since 1-4 has capacity of 13) A(2)5611 Details: 2-1-4-3 5 2-1-4-5 6 A(3)5 Details: 3-4-5 5 A(4)1151026 Details: 4-1-2 11 4-3 5 4-5 10 A(5)10 Details: 5-4-1-2 10 The accumulation degree of a tree is the maximal accumulation degree among its nodes. Here your task is to find the accumulation degree of the given trees. 输入描述: The first line of the input is an integer T which indicates the number of test cases. The first line of each test case is a positive integer n. Each of the following n - 1 lines contains three integers x, y, z separated by spaces, representing there is an edge between node x and node y, and the capacity of the edge is z. Nodes are numbered from 1 to n. All the elements are nonnegative integers no more than 200000. You may assume that the test data are all tree metrics. 输出描述: For each test case, output the result on a single line. 示例1 输入 1 5 1 2 11 1 4 13 3 4 5 4 5 10输出 26题意 看看样例分析应该就明白了 每个节点都有流量求出最大流量是多少 题解 flow【i】表示i点的流量 一个点的流量是怎么来的如果jj是i的子节点的流量小于i与j边的容量flow【i】flow[j]如果大于两点之间的容量flow[i]i与j的流量 i与j的流量就是i与j的边权我们用edge[i][j]表示。 可以得到公式flow[i]∑min(flow[j],edge[i][j]) 因为i有可能有很多子节点所以加在一起 考虑完i之后我们来考虑换根 如图 我们将根从x换成y 题一中以x为根 x的流量来自于y子树2子树3 y的流量来自于子树1 图二中以y为根 x的流量来自子树2子树3 y的流量来自子树1x 我们发现换根后x的流量就没有了y的部分其他都还在此时x的流量就是原本的减去从y流向x的部分new[x]flow[ x ] - min ( flow[ y ] , edge[ x ] [ y ] ),这个new表示x新的流量 我们再看yy的流量多了从x流来的部分y的流量就是flow[y]min(new[x],edge[x][y])因为换根x的流量发生改变上一段所讲那流向y的是现在x的流量而不是换跟前的flow[x]. 换根前后图二中绿色区域没有发生改变也就是父节点改变影响不到子节点 还要注意叶子节点如果x从根变成叶子节点x的儿子只有y当y成为根节点之后x没有了儿子x的流量不是上面的公式而是变成了edge[x][y]因为没有子节点的流量流向x只有x与y的边权值也就是上面讲的式子使用条件是minxyx和y不能为0。 先求出x为根的流量然后依次换根求出最大值 代码 #include bits/stdc.h#define inf 0x7f typedef long long LL; using namespace std; const int maxn 2e5 3;int n;int head[maxn], cnt 0, d[maxn], deg[maxn], f[maxn]; struct edge{int x, y;int next;int w; }edge[maxn * 2];void init() { cnt 0;memset(head, -1, sizeof(head));memset(d, 0, sizeof(d));memset(deg, 0, sizeof(deg)); }void addedge(int x, int y, int w) {edge[cnt].x x;edge[cnt].y y;edge[cnt].w w;edge[cnt].next head[x];head[x] cnt;}void dfs(int root, int fa) {int ans 0;for(int i head[root]; i ! -1; i edge[i].next){int y edge[i].y;if(y fa){continue;}if(deg[y] 1){//如果y只有一个子节点y的流量只能是root与y的边权值 ans edge[i].w;}else{dfs(y, root);ans min(d[y], edge[i].w);}}d[root] ans return ; }//先求出节点x的流量 void dp(int x, int fa) {for(int i head[x]; i ! -1; i edge[i].next){int y edge[i].y;if(edge[i].y fa)continue;if(deg[x] 1){f[y] d[y] edge[i].w;}else{f[y] d[y] min(f[x] - min(d[y], edge[i].w), edge[i].w);//核心公式 }dp(y, x);} }//从x不断换根 int main() {int t;cint;int x, y, w;while(t--){init();//初始化 scanf(%d, n);for(int i 0; i n - 1; i){scanf(%d%d%d, x, y, w);addedge(x, y, w);//添边 addedge(y, x, w);//添边 deg[x];//deg用于判断这个点有几个子节点 deg[y];}int s 1;dfs(s, 0);//求x的流量 f[s] d[s];dp(s, 0);//不断换根 int ans 0;for(int i 1; i n; i){ans max(ans, f[i]);}printf(%d\n, ans);}return 0; }
http://www.pierceye.com/news/157086/

相关文章:

  • 建设个人网站的参考网站及文献辽宁建设工程造价管理网站
  • 如何做360网站的排名新品发布会策划方案ppt
  • 网站后台登陆破解哪里有网站模板下载
  • 网站制作器软件下载建站备案
  • 网页模板下载网站站长素材音效网
  • 青岛网站建设要多少钱关键词优化是怎样收费的
  • 网站国际联网备案WordPress文章分页伪静态
  • 电子商务网站开发的任务书东莞seo关键词搜索关键词
  • 宁乡网站建设在哪小天才电话手表网站
  • 中文响应式网站搜搜网站提交
  • 华为官方网站手机商城首页大淘客网站商品做淘口令
  • 建站公司网站的关键词怎么设置
  • 上海二手房网站制作游戏需要什么技术
  • 湖州市城市建设档案馆网站电子商务网站怎么建
  • 网站超级外链做企业网站大约多少钱
  • 中国网站建设市场分析桂林公司网站搭建
  • 阿里云 企业网站选哪种洞窝app是谁开发的
  • ppt模板做的好的网站有哪些wordpress 多站点设置
  • ui作品集 网站怎么做网站制作加我
  • 自助做网站wordpress更换本地主题
  • 凡科网多页网站怎样做一线城市做网站工资有多少
  • .asp网站怎么做需要一个网站
  • 免费网站代码大全网站开发费入什么费用
  • 网站域名注册多少钱搜索引擎优化工具深圳
  • 学建设网站去哪里学建网站要大约多少钱
  • 网站正则表达式怎么做网站维护一般需要多久
  • 北京网站优化价格有没有做花卉种子的网站啊
  • 资源型网站建设 需要多大硬盘vi设计方案模板
  • 网站怎么做图片放映效果代码怎么生成网站
  • 怎么写代码做网站建投商务网官网