当前位置:网站首页>AT4162 [ARC099C] Independence
AT4162 [ARC099C] Independence
2022-07-22 04:24:00 【心怀凉月】
AT4162 [ARC099C] Independence
对于完全子图,考虑补图性质,即图内任意两个均无边。
若原图可分为两个完全子图,那么补图内子图无边,两子图间可有边,这不正是二分图吗?
染色判断奇环无解,求出每连通块答案,可行性 DP
计算答案即可。
时间复杂度 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;
}
边栏推荐
- Elephant Swap的LaaS方案迅速崛起,构建全新DeFi2.0协议
- 字符编码问题
- stm32使用各种传感器的教程
- sql server2008数据库查询admin密码
- Application level questions of computer network
- Interview questions of computer network transmission layer
- 博途PLC和ABB变频器PN通讯详解
- The LAAS solution of elephant swap has risen rapidly and built a new defi2.0 protocol
- 红队怎么打
- NFT exchange contract development tutorial (solidity & hardhat)
猜你喜欢
交换机与路由器技术:标准ACL、扩展ACL和命名ACL
Vulkan-官方示例解读-子通道
AcWing_ 11. Number of solutions for knapsack problem_ dp
Hybrid hybrid development and jsbridge
模板学堂丨JumpServer安全运维审计大屏
How to configure webrtc protocol for low latency playback on easycvr platform v2.5.0 and above?
[ssm]ssm integration ② (development of functional modules)
6-12 exploit - enumerate SMTP user names
SOC custom IP core -- breathing lamp
AcWing_11. 背包问题求方案数_dp
随机推荐
像素和颜色
Pixels and colors
When the easycvr platform cascades, there is an error prompt. What is the reason why the port is unreachable?
Chant Developer Workbench 2022
洛谷_P1112 波浪数_思维_进制 / 构造 / 枚举
A 15-year-old ABAP veteran's suggestion: understanding these basic knowledge is beneficial to ABAP development
6-12 exploit - enumerate SMTP user names
C server NFS shared folder building and uploading image files
Technologie des commutateurs et des routeurs: ACL standard, ACL étendu et ACL nommé
Mysql database column splicing query writing method
浅谈契约测试
Docker data management case - MySQL data persistence
screen命令使用
MySQL查询计划key_len如何计算
Luogu_ P1112 wave number_ Thinking_ Base / construction / enumeration
用c语言编写一个函数用来删除字符串中的空格并返回空格个数
SFTP creation
Data structure in redis (2): jump table
[initial exploration of STK] create a track to the moon
Informatics Olympiad all in one 1977: [08noip popularization group] stereogram | Luogu p1058 [noip2008 popularization group] stereogram