博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷 P3478 [POI2008]STA-Station
阅读量:5268 次
发布时间:2019-06-14

本文共 3485 字,大约阅读时间需要 11 分钟。

题目描述

The first stage of train system reform (that has been described in the problem Railways of the third stage of 14th Polish OI.

However, one needs not be familiar with that problem in order to solve this task.) has come to an end in Byteotia. The system consists of bidirectional segments of tracks that connect railway stations. No two stations are (directly) connected by more than one segment of tracks.

Furthermore, it is known that every railway station is reachable from every other station by a unique route. This route may consist of several segments of tracks, but it never leads through one station more than once.

The second stage of the reform aims at developing train connections.

Byteasar count on your aid in this task. To make things easier, Byteasar has decided that:

one of the stations is to became a giant hub and receive the glorious name of Bitwise, for every other station a connection to Bitwise and back is to be set up, each train will travel between Bitwise and its other destination back and forth along the only possible route, stopping at each intermediate station.

It remains yet to decide which station should become Bitwise. It has been decided that the average cost of travel between two different stations should be minimal.

In Byteotia there are only one-way-one-use tickets at the modest price of  bythaler, authorising the owner to travel along exactly one segment of tracks, no matter how long it is.

Thus the cost of travel between any two stations is simply the minimum number of tracks segments one has to ride along to get from one stations to the other.

Task Write a programme that:

reads the description of the train system of Byteotia, determines the station that should become Bitwise, writes out the result to the standard output.

给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大

输入输出格式

输入格式:

 

The first line of the standard input contains one integer  () denoting the number of the railway stations. The stations are numbered from  to . Stations are connected by  segments of tracks. These are described in the following  lines, one per line. Each of these lines contains two positive integers  and  (), separated by a single space and denoting the numbers of stations connected by this exact segment of tracks.

 

输出格式:

 

In the first and only line of the standard output your programme should print out one integer - the optimum location of the Bitwise hub.

If more than one optimum location exists, it may pick one of them arbitrarily.

输入样例:

81 45 64 56 76 82 43 4

输出样例:

7
1 //本题相当于洛谷P2986 [USACO10MAR]伟大的奶牛聚集   而且是简化版的题目。。。  2 #include
3 using namespace std; 4 #define ll long long 5 #define man 1000010 6 ll son[man],dis[man],n,f[man]; 7 struct edge 8 { ll next,to;}e[man<<2]; 9 ll head[man<<2],num=0;10 inline void add(ll from,ll to)11 { e[++num].next=head[from];e[num].to=to;head[from]=num;}12 ll precalc(int u,int fa)13 { int tot=0;14 for(ll i=head[u];i;i=e[i].next)15 { ll to=e[i].to;16 if(to==fa) continue;17 ll child=precalc(to,u);18 dis[u]+=dis[to]+child;19 tot+=child;20 }21 return son[u]=tot+1;22 }23 void dfs(int u,int fa)24 { for(int i=head[u];i;i=e[i].next)25 { ll to=e[i].to;26 if(to==fa)continue;27 f[to]=f[u]-son[to]*1+(n-son[to])*1;28 dfs(to,u);29 }30 }31 void ad(int elem)32 { elem+=dis[1];}33 int main()34 { scanf("%lld",&n);35 for(int i=1;i

 

转载于:https://www.cnblogs.com/Slager-Z/p/7695939.html

你可能感兴趣的文章
linux之sort用法
查看>>
Teamcenter10 step-by-step installation in Linux env-Oracle Server Patch
查看>>
Redis-jedis模拟多线程购票
查看>>
聊一聊 Flex 中的 flex-grow、flex-shrink、flex-basis
查看>>
Gcc 安装过程中部分配置
查看>>
Logparser介绍
查看>>
Js实现客户端表单的验证
查看>>
python使用input()来接受字符串时一直报错“xxx is not defined”
查看>>
哈啊哈
查看>>
vue-router在ie9及以下history模式支持
查看>>
linux基础命令--lsof
查看>>
Mysql limit
查看>>
加解密与数据校验
查看>>
stm8s_IAP_xmode串口升级
查看>>
usb 编程知识 总结
查看>>
Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
查看>>
Java基础知识强化之集合框架笔记21:数据结构之 数组 和 链表
查看>>
转:queue
查看>>
[JSOI2016] 最佳团队 (树形DP+01分数规划)
查看>>
mongodb初步理解
查看>>