Vlad and Unfinished Business (图论)
Problem - F - Codeforces
考虑枚举x到y上的路径。路径上的点分为有things的和没有的。有的话就过去跑一次。加上就行了。
/*keep on going and never give up*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define db(x) cerr<<(#x)<<" "<<(x)<<" "<<endl;
#define endl "\n"
#define fast std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn = 2e5+10;
int n,k,son[maxn],pth[maxn],a[maxn];
vector<int>e[maxn];
void dfs1(int x,int fa){for(auto to:e[x]){if(to==fa) continue;dfs1(to,x);son[x]+=son[to];pth[x]|=pth[to];}
}
int dfs2(int x,int fa){int res=0;for(auto to:e[x]){if(to==fa) continue;if(!pth[to]&&son[to]){res+=dfs2(to,x)+2;}}return res;
}
signed main() {fastint t=1;cin>>t;while(t--){cin>>n>>k;for(int i=1;i<=n;i++) son[i]=pth[i]=0,e[i].clear();int x,y;cin>>x>>y;for(int i=1;i<=k;i++){int tep;cin>>tep;son[tep]=1;}pth[y]=1;for(int i=1;i<n;i++){int xx,yy;cin>>xx>>yy;e[xx].push_back(yy);e[yy].push_back(xx);}dfs1(x,0);int ans=0;for(int i=1;i<=n;i++){if(pth[i]) ans+=dfs2(i,i)+1;}cout<<ans-1<<endl;}
}
Vlad and Unfinished Business (图论)相关推荐
- Codeforces Round #787 (Div. 3) F. Vlad and Unfinished Business
翻译: Vlad和Nastya住在一个由
- CF 783 F. Vlad and Unfinished Business
原题链接: https://codeforces.com/contest/1675/problem/F 题目和18946 小美的送花线路 有相似之处.小美送花,只有把最远的结点最后送达才能用时最短. ...
- Matlab数字图像的傅里叶变换(FFT)
查看全文 http://www.taodudu.cc/news/show-6182241.html 相关文章: 使用matlab对图像进行傅里叶变换 [ MATLAB ]离散傅里叶变换(DFT)以及逆 ...
- Codeforces Round #787 (Div. 3)
A. Food for Animals 题目链接:Problem - A - Codeforces 样例输入: 7 1 1 4 2 3 0 0 0 0 0 5 5 0 4 6 1 1 1 1 1 50 ...
- Codeforces Round #787 (Div. 3)补题
目录: 官网链接 E. Replace With the Previous, Minimize F. Vlad and Unfinished Business G. Sorting Pancakes ...
- Codeforces Round #787 (Div. 3) ABCDEF
文章目录 一.A. Food for Animals? 二.B - Make It Increasing 三.C - Detective Task 四.D - Vertical Paths 五.E - ...
- 35个立体动感的视差滚动效果网站作品
这篇文章收集了35个具有立体动感效果的视差滚动网页设计作品分享给大家.视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验.作为今 ...
- 视差滚动(Parallax Scrolling)效果的原理和实现
视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验.作为今年网页设计的热点趋势,越来越多的网站应用了这项技术. 可以先看看效果: ...
- 40个视差滚动效果网站的新技术应用
视差滚动效果,是现代网页设计的趋势,,他是使用多个背景图片,但是移动背景不同步,.整体效果,给观众一个无缝的和有趣的浏览体验,这样的网站目前越来越流行,如果你会这样的技术,肯定是先学先收益,今天就给大 ...
- and5.1PowerManagerService深入分析(四)PMS与Display模块
and5.1PowerManagerService深入分析(四)PMS与Display模块 转自:http://blog.csdn.net/kc58236582/article/details/480 ...
最新文章
- C++ OJ在线编程常见输入输出技巧与示例
- 第四范式团队KDD Cup世界冠军方案详解:解密共享出行场景中的优化问题
- 【Python CheckiO 题解】Largest Rectangle in a Histogram
- android oneshot自动播放bug,移动端常见bug汇总001
- 别乱用了,这才是 SpringBoot 停机的正确方式!!!
- linux中 在文件中写入一句话怎么写_shell文件处理笔记之插入文本到文件的方法...
- HTML表单input里面的value的作用
- 算法:翻转图片Rotate Image
- 修改vscode代码字体大小
- 点云 数据 (偏向于研究大小)
- 淘宝自动下单软件//下单神器、、
- web3调用智能合约取事件
- [Maven实战-许晓斌]-[第二章]-2.6 NetBeans上面安装Maven插件
- 什么是英特尔® Edison 模块?
- android 9平板电脑截屏,平板电脑怎么截图 平板电脑截图方法【详解】
- 物联网实训室建设方案(2020完整版)
- 侯捷c++课程学习一
- socketio单聊,群聊
- sed在行首插入tab制表符
- 传奇自定义技能栏技术分享-GEE
热门文章
- php生成服务器证书pfx,使用PHP使用.pfx证书签署XML文件
- 理解LINQ预编译查询(Compiled LINQ)
- 谢烟客---------Linux之网络基础知识
- Excel入门之快速录入数据
- 基于B站服务器宕机事故,小鸟云聊聊高防云服务器选择技巧
- IT运维工程师要会什么?
- [Android]按阶段编译Android kernel中的代码
- vs2016 程序在vs2019 运行,显示无法找到 Intel C++ Compiler XE14.0解决方案
- 万字总结,行业分析到底应该怎么做!
- 解决微信emjoy特殊符号插入数据库出错