当前位置:网站首页>AT4162 [ARC099C] Independence
AT4162 [ARC099C] Independence
2022-07-22 16:42:00 【Have a cold moon in your heart】
AT4162 [ARC099C] Independence
For complete subgraphs , Consider the properties of complementary graphs , That is, any two in the graph have no edges .
If the original graph can be divided into two complete subgraphs , Then the subgraph in the complement graph is boundless , There can be edges between two subgraphs , This is exactly a bipartite graph ?
Coloring judges that odd rings have no solution , Find the answer of each connected block , The feasibility of DP
Calculate the answer .
Time complexity O ( n ) \mathcal O(n) O(n).
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define ha putchar(' ')
#define he putchar('\n')
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
const int _ = 705;
int n, m, cnt, ans, t[3], c[_], t1[_], t2[_];
bool mp[_][_], f[_][_];
int tot, head[_], to[_ * _], nxt[_ * _];
void add(int u, int v) {
to[++tot] = v, nxt[tot] = head[u], head[u] = tot;
to[++tot] = u, nxt[tot] = head[v], head[v] = tot;
}
void dfs(int u) {
t[c[u]]++;
for (int i = head[u]; i; i = nxt[i]) {
int v = to[i];
if (c[v]) {
if (c[u] == c[v]) {
write(-1);
exit(0);
}
continue;
}
c[v] = (c[u] == 1 ? 2 : 1);
dfs(v);
}
}
signed main() {
n = read(), m = read(), ans = n * n;
for (int i = 1, u, v; i <= m; ++i) {
u = read(), v = read();
mp[u][v] = mp[v][u] = 1;
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
if (!mp[i][j]) add(i, j);
for (int i = 1; i <= n; ++i)
if (!c[i]) {
cnt++, c[i] = 1, t[1] = t[2] = 0;
dfs(i);
t1[cnt] = t[1], t2[cnt] = t[2];
}
f[0][0] = 1;
for (int i = 1; i <= cnt; ++i)
for (int j = 0; j <= n; ++j)
if (f[i - 1][j])
f[i][j + t1[i]] = f[i][j + t2[i]] = 1;
for (int i = 0; i <= n; ++i)
if (f[cnt][i]) ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
write(ans), he;
return 0;
}
边栏推荐
- screen命令使用
- 高数_第2章多元函数微分学_隐函数的偏导数
- How to configure webrtc protocol for low latency playback on easycvr platform v2.5.0 and above?
- Luogu_ P1112 wave number_ Thinking_ Base / construction / enumeration
- Leetcode 172. 阶乘后的零
- MySQL查询计划key_len如何计算
- Complex network modeling (propagation phenomenon on the network)
- Dc-4-range practice
- Fastjson 代码执行 CVE-2022-25845
- 正则表达式相关
猜你喜欢
toString()及重写的作用与应用
Mask RCNN source code explanation
This easy-to-use office network optimization tool is free
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
NFT exchange contract development tutorial (solidity & hardhat)
高数_第3章重积分
What is SCM? What are the components of SCM?
交换机与路由器技术:标准ACL、扩展ACL和命名ACL
PXE network installation
Win10系统打开什么都是反应比平时慢,转圈等待1分钟如何解决?
随机推荐
交换机与路由器技术:OSPF路由重分发、OSPF的NSSA区域和OSPF虚链路
Kingbasees Security Guide for Jincang database -- 2.1. about database security threats
【Unity】 UI跟随3D物体,世界坐标转UI坐标
Glide source code analysis
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
ARC110F Esoswap
C语言程序练习——(写一个函数,它的原形是int continumax(char *outputstr,char *intputstr))
Interview questions about network related concepts
抖音Tiktok- 获取抖音视频详情接口
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
Gold warehouse database kmonitor usage guide --2. monitoring indicators
postgreSQL中update set a=(select ) 应该如何写?
Technologie des commutateurs et des routeurs: ACL standard, ACL étendu et ACL nommé
AT4163 [ARC099D] Eating Symbols Hard
Character encoding problem
[ssm]ssm integration ③ (interface test)
Diversified distribution methods of NFT
Transparent transmission of punctual atom Lora wireless serial port point-to-point communication and Its Precautions
ECCV 2022 | correction des dommages importants au rendement de la cible causés par le fpn: Vous devriez regarder tous les objets
Kingbasees Security Guide for Jincang database -- 2.2. prevention of kingbasees' threats to database security