Cable Protection
题目大意:求一颗基环树的最小点覆盖。
题解:其实是一道比较板子的树形dp,dp[i][0/1]表示取或者不取i点的最小点。但是首先我们要把基环树断开,然后分别考虑a被覆盖和b被覆盖的情况。
dp[i][0]=∑min(dp[j][0],dp[j][1])
d p [ i ] [ 1 ] = ∑ d p [ j ] [ 0 ]
AC_code:
1 int dp[maxn][3];
2 int a,b,flag;
3 vector<int>g[maxn];
4 void dfs(int x,int fa){
5 dp[x][0]=dp[x][1]=0;
6 for(int i=0;i<g[x].size();i++){
7 int v=g[x][i];
8 if(fa==v) continue;
9 dfs(v,x);
10 dp[x][0]+=min(dp[v][0],dp[v][1]);
11 dp[x][1]+=dp[v][0];
12 }
13 dp[x][0]++;
14 if(x==b&&flag==2) dp[x][1]=dp[x][0];
15 }
16 void run(){
17 int n=rd(),m=rd();
18 rep(i,1,n+m){
19 int x=rd(),y=rd();
20 if(!flag&&x<n&&y<n){
21 a=x,b=y;
22 flag=1;
23 continue;
24 }
25 g[x].push_back(y);
26 g[y].push_back(x);
27 }
28 int ans=inf;
29 flag=1;
30 dfs(a,-1);
31 ans=min(dp[a][0],ans);
32 flag=2;
33 dfs(a,-1);
34 ans=min(ans,min(dp[a][0],dp[a][1]));
35 printf("%d\n",ans);
36 }
Cable Protection的更多相关文章
- POJ 1966 Cable TV Network
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4702 Accepted: 2173 ...
- ASP.NET Core 数据保护(Data Protection 集群场景)【下】
前言 接[中篇],在有一些场景下,我们需要对 ASP.NET Core 的加密方法进行扩展,来适应我们的需求,这个时候就需要使用到了一些 Core 提供的高级的功能. 本文还列举了在集群场景下,有时候 ...
- ASP.NET Core 数据保护(Data Protection)【中】
前言 上篇主要是对 ASP.NET Core 的 Data Protection 做了一个简单的介绍,本篇主要是介绍一下API及使用方法. API 接口 ASP.NET Core Data Prote ...
- ASP.NET Core 数据保护(Data Protection)【上】
前言 上一篇博客记录了如何在 Kestrel 中使用 HTTPS(SSL), 也是我们目前项目中实际使用到的. 数据安全往往是开发人员很容易忽略的一个部分,包括我自己.近两年业内也出现了很多因为安全问 ...
- MacOS changed System Integrity Protection status
禁止 System Integrity Protection 按住 command + R 重启系统 进入单用户模式 启动bash工具: 输入: csrutil disable 输入:reboot 启 ...
- "System Protection" is disabled in Win10 default settings
We could find some important clue in Restore Point because "System Protection" of volume C ...
- 挖掘机力矩限制器/挖掘机称重系统/挖泥机称重/Excavators load protection/Load moment indicator
挖掘机力矩限制器是臂架型起重机机械的安全保护装置,本产品采用32位高性能微处理器为硬件平台 ,软件算法采用国内最先进的液压取力算法,该算法吸收多年的现场经验,不断改进完善而成.本产品符合<GB1 ...
- Process Kill Technology && Process Protection Against In Linux
目录 . 引言 . Kill Process By Kill Command && SIGNAL . Kill Process By Resource Limits . Kill Pr ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
随机推荐
- 手撕 part1
1.宏定义三个数最大值 挺有意思 max((a), (b), (c)) (a) > (b)? ((a) > (c)? (a) : (c)) ((b) > (c)? (b) : (c) ...
- Vue dynamic component All In One
Vue dynamic component All In One Vue 动态组件 vue 2.x https://vuejs.org/v2/guide/components-dynamic-asyn ...
- 使用 js 实现十大排序算法: 快速排序
使用 js 实现十大排序算法: 快速排序 QuickSort 快速排序 /** * * @author xgqfrms * @license MIT * @copyright xgqfrms * @c ...
- OOP & 模块化, 多态, 封装
OOP 面向对象编程 (OOP) 是用抽象方式创建基于现实世界模型的一种编程模式.它使用先前建立的范例,包括模块化,多态和封装几种技术. 在 OOP 中,每个对象能够接收消息,处理数据和发送消息给其他 ...
- webpack 5
webpack 5 webpack 5 requires at least Node.js 10.13.0 (LTS). https://webpack.js.org/migrate/5/ https ...
- cache-control config & http cache storage location control
cache-control config & http cache storage location control cache-control 设置 where is the storage ...
- git & Angular git commit 规范
git & Angular git commit 规范 https://github.com/angular/angular/commits/master https://github.com ...
- APP 金刚区图标设计 & UI
APP 金刚区图标设计 & UI https://www.zcool.com.cn/article/ZNzk4Njg0.html
- APC推出鞋底缓震科技 两款中高端跑鞋将陆续上市
近日,英国知名运动品牌APC(公司编号:08703733)推出了全新的鞋底缓震科技 NOVR,该项技术将首先应用于两款跑步鞋上,随后陆续应用到其他重点鞋类产品. 是对于各大运动品牌来说,鞋底研发一直是 ...
- NGK Global技术开源,开启跨链全生态
消息显示,新兴公链项目NGK Global已经完成了自己的开源计划,基于自己创新性的跨链通讯交互方案,开源后的NGK Global将面向全生态节点,提供高效.自由.无边界的公链生态系统. 目前,大家对 ...