[atARC099E]Independence
考虑这张图的反图,相当于这两个集合内部没有边,这也就是二分图的限制
换言之,我们要将这张图黑白染色(不能则为-1),$x$即为某种颜色的数个数
对于一个联通块,记连通块大小为$sz$,则白色点个数为$w$或$sz-w$(交换两种颜色)
背包转移即可,时间复杂度为$o(n^{2})$,可以通过此题

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 705
4 struct ji{
5 int nex,to;
6 }edge[N*N];
7 bitset<N>f;
8 int E,n,m,x,y,ans,head[N],e[N][N],vis[N];
9 void add(int x,int y){
10 edge[E].nex=head[x];
11 edge[E].to=y;
12 head[x]=E++;
13 }
14 int dfs(int k,int p){
15 if (vis[k]>=0)return vis[k]==p;
16 x+=(!p);
17 y+=p;
18 vis[k]=p;
19 for(int i=head[k];i!=-1;i=edge[i].nex)
20 if (!dfs(edge[i].to,p^1))return 0;
21 return 1;
22 }
23 int c(int k){
24 return k*(k-1)/2;
25 }
26 int main(){
27 scanf("%d%d",&n,&m);
28 memset(head,-1,sizeof(head));
29 for(int i=1;i<=m;i++){
30 scanf("%d%d",&x,&y);
31 e[x][y]=e[y][x]=1;
32 }
33 for(int i=1;i<=n;i++)
34 for(int j=1;j<=n;j++)
35 if ((i!=j)&&(!e[i][j]))add(i,j);
36 memset(vis,-1,sizeof(vis));
37 f[0]=1;
38 for(int i=1;i<=n;i++)
39 if (vis[i]<0){
40 x=y=0;
41 if (!dfs(i,0)){
42 printf("-1");
43 return 0;
44 }
45 f=((f<<x)|(f<<y));
46 }
47 ans=c(n);
48 for(int i=1;i<n;i++)
49 if (f[i])ans=min(ans,c(i)+c(n-i));
50 printf("%d",ans);
51 }
[atARC099E]Independence的更多相关文章
- 控制反转(IOC: Inverse Of Control) & 依赖注入(DI: Independence Inject)
举例:在每天的日常生活中,我们离不开水,电,气.在城市化之前,我们每家每户需要自己去搞定这些东西:自己挖水井取水,自己点煤油灯照明,自己上山砍柴做饭.而城市化之后,人们从这些琐事中解放了出来,城市中出 ...
- Independence独立
Independence refers to the degree to which each test case stands alone. That is, does the success or ...
- [PGM] Bayes Network and Conditional Independence
2 - 1 - Semantics & Factorization 2 - 2 - Reasoning Patterns 2 - 3 - Flow of Probabilistic Influ ...
- AtCoder Regular Contest 099 (ARC099) E - Independence 二分图
原文链接https://www.cnblogs.com/zhouzhendong/p/9224878.html 题目传送门 - ARC099 E - Independence 题意 给定一个有 $n$ ...
- [Bayes] prod: M-H: Independence Sampler for Posterior Sampling
M-H是Metropolis抽样方法的扩展,扩展后可以支持不对称的提议分布. 对于M-H而言,根据候选分布g的不同选择,衍生出了集中不同的变种: (1)Metropolis抽样方法 (2)随机游动Me ...
- GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树
G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...
- C# 控制反转(IOC: Inverse Of Control) & 依赖注入(DI: Independence Inject)
举例:在每天的日常生活中,我们离不开水,电,气.在城市化之前,我们每家每户需要自己去搞定这些东西:自己挖水井取水,自己点煤油灯照明,自己上山砍柴做饭.而城市化之后,人们从这些琐事中解放了出来,城市中出 ...
- 【线性代数】3-5:独立性,基和维度(Independence,Basis and Dimension)
title: [线性代数]3-5:独立性,基和维度(Independence,Basis and Dimension) categories: Mathematic Linear Algebra ke ...
- 【读书笔记】:MIT线性代数(4):Independence, Basis and Dimension
Independence: The columns of A are independent when the nullspace N (A) contains only the zero vecto ...
随机推荐
- 详解package-lock.json的作用
目录 详解package-lock.json package-lock.json的作用 版本号的定义规则与前缀对安装的影响 改动package.json后依旧能改变项目依赖的版本 当前项目的真实版本号 ...
- 题解 [NOI2019]弹跳
题目传送门 题目大意 给出 \(n\) 做城市,每座城市都有横纵坐标 \(x,y\).现在给出 \(m\) 个限制 \(p,t,l,r,d,u\),表示从 \(p\) 城市出发,可以花费 \(t\) ...
- 2020.12.14--Codeforces Round #104 (Div.2)补题
C - Lucky Conversion CodeForces - 146C Petya loves lucky numbers very much. Everybody knows that luc ...
- 无法获取指向控制台的文件描述符 (couldn't get a file descriptor referring to the console)
背景 最近收拾东西,从一堆杂物里翻出来尘封四年多的树莓派 3B 主机来,打扫打扫灰尘,接上电源,居然还能通过之前设置好的 VNC 连上.欣慰之余,开始 clone 我的 git 项目,为它们拓展一个新 ...
- scala基础篇 源码中 :_*的作用
在scala源码中有大量的:_*,其作用是把Array.list转换为参数列表,作为变长参数传入参数列表 例子: def sumx(a:Int*)={ a.sum } val a=Range(1,9) ...
- 四、Implementation: The Building Blocks 实现:构件
四.Implementation: The Building Blocks 实现:构件 This is the essential part of this guide. We will introd ...
- mall笔记
介绍 SpringBoot.SpringCloud.SpringCloudAlibaba.Nacos.Sentinel.Seata整合demo. 软件架构 JDK 1.8 Spring Boot 2. ...
- 第二次Scrum Metting
日期:2021年4月25日会议主要内容概述:前后端针对WebAPI进行协调与统一工作,商量接下来两日计划:敲定部分设计细节. 一.进度情况 组员 负责 两日内已完成的工作 后两日计划完成的工作 工作中 ...
- Vue3+Typescript+Node.js实现微信端公众号H5支付(JSAPI v3)教程--各种填坑
----微信支付文档,不得不说,挺乱!(吐槽截止) 功能背景 微信公众号中,点击菜单或者扫码,打开公众号中的H5页面,进行支付. 一.技术栈 前端:Vue:3.0.0,typescript:3.9.3 ...
- 2021.8.6考试总结[NOIP模拟32]
T1 smooth 考场上水个了优先队列多带个$log$,前$80$分的点跑的飞快,后面直接萎了. 其实只需开$B$个队列,每次向对应队列中插入新的光滑数,就能保证队列中的数是单调的. 为了保证不重, ...