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条长 ...
随机推荐
- BZOJ1001 狼抓兔子(网络流转最短路:对偶图)
题意: 给一个如图形式的\(n*m\)的方格,从左上走到右下,给出边权,问分成两块所需的最小代价.\(n,m\leq1000\). 思路: 显然是个最小割,但是\(O(n^2m)\)的复杂度很高,虽然 ...
- Springboot 基本认识
不管是 spring cloud alibaba 还是 spring cloud netflix,都 是基于 springboot 这个微框架来构建的,所以我希望花一 点时间来讲一下 springbo ...
- Prettier All In One
Prettier All In One .prettierrc.js / .prettierrc / .prettierrc.json module.exports = { singleQuote: ...
- HTML script tag type all in one
HTML script tag type all in one script type https://developer.mozilla.org/en-US/docs/Web/HTML/Elemen ...
- how HTTPS works
How HTTPS works HTTPS comic tutorials How HTTPS works ...in a comic! https://howhttps.works/ A cat e ...
- koa url path & koa-router
koa url path & koa-router url path & regex koa path router "use strict"; /** * * @ ...
- React Big Changes All in One
React Big Changes All in One React 重大更新 React Versions React 版本变更 https://reactjs.org/versions/ sema ...
- Python & file operation mode
Python & file operation mode create/read/write/append mode https://docs.python.org/3/library/fun ...
- calendar merge date
calendar merge date componentDidMount () { const { monthDays, // monthDates, } = this.props; const d ...
- classnames & React & taro
classnames & React & taro classnames https://www.npmjs.com/package/classnames demo https://g ...