题目大意:求一颗基环树的最小点覆盖。

题解:其实是一道比较板子的树形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的更多相关文章

  1. POJ 1966 Cable TV Network

    Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4702   Accepted: 2173 ...

  2. ASP.NET Core 数据保护(Data Protection 集群场景)【下】

    前言 接[中篇],在有一些场景下,我们需要对 ASP.NET Core 的加密方法进行扩展,来适应我们的需求,这个时候就需要使用到了一些 Core 提供的高级的功能. 本文还列举了在集群场景下,有时候 ...

  3. ASP.NET Core 数据保护(Data Protection)【中】

    前言 上篇主要是对 ASP.NET Core 的 Data Protection 做了一个简单的介绍,本篇主要是介绍一下API及使用方法. API 接口 ASP.NET Core Data Prote ...

  4. ASP.NET Core 数据保护(Data Protection)【上】

    前言 上一篇博客记录了如何在 Kestrel 中使用 HTTPS(SSL), 也是我们目前项目中实际使用到的. 数据安全往往是开发人员很容易忽略的一个部分,包括我自己.近两年业内也出现了很多因为安全问 ...

  5. MacOS changed System Integrity Protection status

    禁止 System Integrity Protection 按住 command + R 重启系统 进入单用户模式 启动bash工具: 输入: csrutil disable 输入:reboot 启 ...

  6. "System Protection" is disabled in Win10 default settings

    We could find some important clue in Restore Point because "System Protection" of volume C ...

  7. 挖掘机力矩限制器/挖掘机称重系统/挖泥机称重/Excavators load protection/Load moment indicator

    挖掘机力矩限制器是臂架型起重机机械的安全保护装置,本产品采用32位高性能微处理器为硬件平台 ,软件算法采用国内最先进的液压取力算法,该算法吸收多年的现场经验,不断改进完善而成.本产品符合<GB1 ...

  8. Process Kill Technology && Process Protection Against In Linux

    目录 . 引言 . Kill Process By Kill Command && SIGNAL . Kill Process By Resource Limits . Kill Pr ...

  9. POJ 1064 Cable master (二分)

    题目链接: 传送门 Cable master Time Limit: 1000MS     Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...

随机推荐

  1. sentry can not delete release bug

    sentry can not delete release bug bug $ ./node_modules/@sentry/cli/bin/sentry-cli releases list $ ./ ...

  2. HTML5 dataset All In One

    HTML5 dataset All In One dataset https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignEleme ...

  3. React & Special Props Warning

    React & Special Props Warning key & ref demo index.js:1 Warning: Comment: key is not a prop. ...

  4. TensorFlow & Machine Learning

    TensorFlow & Machine Learning TensorFlow 实战 传统方式 规则 + 数据集 => 答案 无监督学习 机器学习 神经元网络 答案 + 数据集 =&g ...

  5. Interview Questions All In One

    Interview Questions All In One web fullstack System Design Operating System Object-Oriented Design O ...

  6. expo-cli & React Native

    expo-cli https://reactnative.dev/docs/environment-setup You will only need a recent version of Node. ...

  7. vue & npm & components & plugins

    vue & npm & components & plugins how to publish an vue ui component to npm? https://www. ...

  8. web & js & touch & gesture

    web & js & touch & gesture 触摸 & 手势 https://caniuse.com/#feat=touch js https://develo ...

  9. taro ENV & NODE_ENV & process.env

    taro ENV & NODE_ENV & process.env https://github.com/NervJS/taro-ui/blob/dev/src/common/util ...

  10. MongoDB的下载、安装与部署

    1.什么是MongoDB? 它是介于关系型数据库和非关系型数据库之间的一种NoSQL数据库,用C++编写,是一款集敏捷性.可伸缩性.扩展性于一身的高性能的面向文档的通用数据库. 2.为什么要用Mong ...