codeforces 700B
2016-07-25 21:04
288 查看
在给的点中选出一对对点,让每两个点的距离和最大
乱搞,做过这种关于类型的,这次算比较简单的。
乱搞,做过这种关于类型的,这次算比较简单的。
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <iostream> #include <vector> #include <cmath> #include <map> #include <string> #include <stack> #include <queue> using namespace std; vector<int>edge[200100]; int vis[200100]; int num[200100]; int n,k; long long ans; void dfs1(int root,int father) { if (vis[root]) num[root]=1; for (int i=0;i<edge[root].size();i++) { int v=edge[root][i]; if (v==father) continue; dfs1(v,root); num[root]+=num[v]; } } void dfs2(int root,int father) { for (int i=0;i<edge[root].size();i++) { int v=edge[root][i]; if (v==father) continue; ans+=min(num[v],2*k-num[v]); dfs2(v,root); } } int main() { scanf ("%d%d",&n,&k); int temp=2*k; while (temp--) { int p; scanf ("%d",&p); vis[p]=1; } n--; while (n--) { int t1,t2; scanf ("%d%d",&t1,&t2); edge[t1].push_back(t2); edge[t2].push_back(t1); } dfs1(1,0); dfs2(1,0); printf ("%I64d\n",ans); return 0; }
相关文章推荐
- hdoj1702ACboy needs your help again!
- ImageNet Classification with Deep Convolutional Neural Networks
- SDKD 2016 Summer Single Contest #12 .G
- 【HDU 2602】Bone Collector(01背包)
- 文本居中
- CodeForces 540A Combination Lock
- 2016/07/25 初识java
- 版本管理工具(待续)
- session入mysql
- javascript正则表达式
- DOM、SAX、JDOM、DOM4J以及PULL在XML文件解析中的工作原理以及优缺点对比
- DOM、SAX、JDOM、DOM4J以及PULL在XML文件解析中的工作原理以及优缺点对比
- 最美公式:世上最伟大的十个公式
- 几乎零配置产生Nuget包的库:White Tie
- [LeetCode练习题-C语言]203. Remove Linked List Elements
- Linux运维学习历程-第二天-虚拟机的配置
- 清除confluent 在zookeeper中的数据
- Android socket通信 readline方法阻塞
- 异常捕获
- Ubuntu下安装Python