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条长 ...
随机推荐
- 经济学,金融学:资产证券化 ABS
经济学,金融学:资产证券化 ABS ABS 资产支持证券 蚂蚁金服如何把30亿变成3000亿?资产证券化 前几天,花呗借呗的东家蚂蚁集团在上市前夕被监管部门叫停,因为这则新闻广大网民都听说了一个概念: ...
- koa url path & koa-router
koa url path & koa-router url path & regex koa path router "use strict"; /** * * @ ...
- Android Studio & SDK & JDK & setting path
Android Studio & SDK & JDK & setting path https://developer.android.com/studio/intro/upd ...
- position: absolute; not work
position: absolute; not work https://stackoverflow.com/questions/11928294/css-position-absolute-with ...
- windows driver 简单的驱动和通信
sysmain.c #pragma once #pragma warning(disable: 4100) #include <ntifs.h> #include <ntddk.h& ...
- svg all in one
svg all in one show svg in html methods https://vecta.io/blog/best-way-to-embed-svg https://css-tric ...
- js 生成Excel
https://www.npmjs.com/package/xlsx 安装依赖 npm install xlsx Example import * as XLSX from "xlsx&qu ...
- NGK数字增益平台中如何分配代币产出
最近很多朋友听说NGK公链的主网和数字增益平台即将上线以后都纷纷表示非常感兴趣,已经基本了解了NGK代币的产出方式,但还是对代币产出分配的问题不是很明确.今天小编就给大家科普一下,NGK代币在NGK数 ...
- 【PY从0到1】 一文掌握Pandas量化进阶
# 一文掌握Pandas量化进阶 # 这节课学习Pandas更深的内容. # 导入库: import numpy as np import pandas as pd # 制作DataFrame np. ...
- MySQL的简单使用方法备忘
这只是一篇我的个人备忘录,写的是我常用的命令.具体可以参考"菜鸟教程" https://www.runoob.com/mysql/mysql-tutorial.html 登录(用户 ...