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

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

显然这个是个并查集

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

可以贪心的想,一共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. python -- peewee处理数据库连接

    目前,实现了的Database子类有三个:SqliteDatabase.MySQLDatabase.PostgresqlDatabase class SqliteDatabase(Database) ...

  2. HDU 1004 Let the Balloon Rise(map的使用)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  3. SQL引用DAL

    步骤:https://www.cnblogs.com/grom/articles/8981116.html 异常: 解决方案: 执行 ALTER DATABASE [DBName] SET TRUST ...

  4. VB

    on error resume next: 从该语句开始,遇到错误时程序不会中止,也不会出现错误提示,将继续运行.作用范围直至程序结束或语句所在函数等结束 Public Property :可读也可写 ...

  5. 嵌入式C语言自我修养 08:变参函数的格式检查

    8.1 属性声明:format GNU 通过 __atttribute__ 扩展的 format 属性,用来指定变参函数的参数格式检查. 它的使用方法如下: __attribute__(( forma ...

  6. PHP-学习笔记-进阶

    PHP-学习笔记-进阶 PHP类和对象之定义类的方法 访问控制的关键字代表的意义为: public:公开的 protected:受保护的 private:私有的 我们可以这样定义方法: class C ...

  7. 用k8s构建生产环境下应用服务

    1.生成镜像 见https://www.cnblogs.com/mushou/p/9713741.html,把测试成熟的应用添加到tomcat镜像生成新的镜像,用ansible部署到集群的几点服务器中 ...

  8. parted 命令学习

    背景:fdisk命令是针对MBR分区进行操作,MBR分区因为自身设计原因,不能处理大于2TB的硬盘,并且只能有4个分区.针对大于2TB的硬盘,需要采用GPT分区,使用parted命令进行操作 part ...

  9. Framwork框架-网络客户端的使用

    1.引入头文件 #include "Comm.h" 2.派生自框架基类CProtocolCpMgr class NetManager : public CProtocolCpMgr ...

  10. MFC 中的 Value 和 Control

    一.變量類型不同:control 型变量是这个控件所属类的一个实例(对象),控制對象的變量.即變量代表對象本身.代表這個人!value 是用来传递数据,不能对控件进行其它的操作.向變量傳遞數據.代表這 ...