首先我们如果满足三缺一,那么必有同行和同列的点

如果两行有同列的数,我们可以设想,他们最后会全部填充成为两者啥都有的情况

显然这个是个并查集

现在我们有了很多集合,每个集合自己可以进行三缺一操作,但是集合有缺陷,集合里面的人都没有的列数,那就没法搞

可以贪心的想,一共k个集合的话,把k个集合连接起来需要k-1个新点,如果还有列没有,那就需要这些列需要新店

除此之外,一开始没有讨论有些行压根没有点,这些行也需要点去开辟疆土

综上所述,一开始论述的时候将行和列交换也是合理的

人总喜欢在伤心,劳累,挫折时放纵自己,但这之后把你引向深渊

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 200005;
const int INF = 0x3f3f3f3f; int f[N]; //col
int find(int x) { return f[x] == x ? x : (f[x] = find(f[x])); } vector<int> row[N];
vector<int> col[N]; vector<int> part[N];
int has[N]; int tag[N];
int main() {
int n, m, q;
while(~scanf("%d %d %d", &n, &m, &q)) {
for(int i = 1; i <= m; ++i) f[i] = i;
for(int i = 0; i < q; ++i) {
int a, b;
scanf("%d %d", &a, &b);
row[a].push_back(b);
tag[a] ++;
col[b].push_back(a);
has[b] = 1;
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j < row[i].size(); ++j) {
int t1 = row[i][0];
int t2 = row[i][j];
int f1 = find(t1); int f2 = find(t2);
if(f1 != f2) {
f[f2] = f1;
}
}
} for(int i = 1; i <= m; ++i) {
int tt = find(i);
part[tt].push_back(i);
} int cnt = 0; int cntPart = 0;
for(int i = 1; i <= m; ++i) {
if(!has[i]) continue;
if(part[i].size() > 0) {
cntPart ++;
cnt += part[i].size();
}
} int result = 0;
for(int i = 1; i <= n; ++i) {
if(!tag[i])
result ++;
}
// printf("%d\n", cnt);
printf("%d\n", result + cntPart - 1 - cnt + m);
}
return 0;
}

Codeforces Round #500 (Div. 2) D - Chemical table的更多相关文章

  1. Codeforces Round #500 (Div. 2) [based on EJOI]

    Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...

  2. Codeforces Round 500 (Div 2) Solution

    从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...

  3. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  4. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  5. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

  6. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #140 (Div. 1) D. The table 构造

    D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...

  8. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  9. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

随机推荐

  1. GIT和GitHub的使用总结

    目录 一.GIT初始化设置: 创建密钥 添加远程仓库 用户名邮箱配置 Clone远程仓库 创建本地仓库 代理设置 自定义操作 二.GIT基本操作 添加到暂存区区 提交 删除 版本回退 撤销修改 三.G ...

  2. (转)查看mysql数据库连接数、并发数相关信息

    查看mysql数据库连接数.并发数相关信息 1.mysql> show status like 'Threads%';+-------------------+-------+| Variabl ...

  3. OPENGL绘制文字

    OPENGL没有提供直接绘制文字的功能,需要借助于操作系统. 用OPENGL绘制文字比较常见的方法是利用显示列表.创建一系列显示列表,每个字符对应一个列表编号.例如,'A'对应列表编号1000+'A' ...

  4. webapi文件上传和下载

    文件上传我们可以做上传文件保存到图片与导入数据,下载可以下载多样的文件. 上传:实例是单个文件导入 NopiHelper:地址 ①简单的上传图片进行保存,方法跟MVC中的一样 <form nam ...

  5. G1 GC日志:Application time: 0.8766273 seconds

    启动日志一直循环: 1.159: Application time: 0.8766273 seconds 1.160: Total time for which application threads ...

  6. Oracle分析函数(一)

    (一)分析函数语法 function_name(<argument>,<argument>...) over(<partition by clause><or ...

  7. 建立复数类Complex,并且进行赋值,求和,取模等操作

    #include "pch.h" #include <iostream> #include<cmath> using namespace std; clas ...

  8. Linux基础-2.目录文件的浏览、管理及维护

    1.Linux文件系统的层次结构 1)了解Linux文件系统的树状结构: 在Linux或UNIX操作系统中,所有的文件和目录都被组织成一个以根节点开始的倒置树状结构 2)掌握目录的定义:目录相当于Wi ...

  9. python 用户注册用户名

    实现用户注册网站,编辑用户名时判断是否已经存在: 若存在则提示“The name you used have already existed,please change your name” 若不存在 ...

  10. [试玩] FMXLinux (Firemonkey for Linux) Linux 桌面开发(第三方插件)

    FMXLinux 是一个可以用来开发 Linux 桌面软件的第三方插件,它需要配合 Delphi 10.2 Toyko 官网:http://www.fmxlinux.com/ 使用方法:开启 FMX ...