C - Points, Lines and Ready-made Titles

把行列看成是图上的点, 一个点(x, y)就相当于x行 向 y列建立一条边, 我们能得出如果一个联通块是一棵树方案数是2 ^ n - 1

否则是2 ^ n。 各个联通块乘起来就是答案。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 4e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, x[N], y[N], hs[N], tot;
int bin[N], fa[N], ecnt[N], pcnt[N]; int getRoot(int x) {
return x == fa[x] ? x : fa[x] = getRoot(fa[x]);
} int main() {
for(int i = bin[] = ; i < N; i++) bin[i] = bin[i - ] * % mod;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
hs[++tot] = x[i];
hs[++tot] = y[i];
}
sort(hs + , hs + + tot);
tot = unique(hs + , hs + + tot) - hs - ;
for(int i = ; i <= n; i++) {
x[i] = lower_bound(hs + , hs + + tot, x[i]) - hs;
y[i] = lower_bound(hs + , hs + + tot, y[i]) - hs;
}
for(int i = ; i <= * tot; i++) fa[i] = i, ecnt[i] = , pcnt[i] = ;
for(int i = ; i <= n; i++) {
int X = getRoot(x[i]);
int Y = getRoot(y[i] + tot);
if(X == Y) {
ecnt[X]++;
} else {
ecnt[X] += ecnt[Y] + ;
pcnt[X] += pcnt[Y];
fa[Y] = X;
}
}
LL ans = ;
for(int i = ; i <= * tot; i++) {
if(i != fa[i]) continue;
if(ecnt[i] < pcnt[i]) ans = (ans * (bin[pcnt[i]] - + mod) % mod) % mod;
else ans = (ans * bin[pcnt[i]]) % mod;
}
printf("%lld\n", ans);
return ;
} /*
*/

最新文章

  1. struts2学习笔记--ActionContext对象
  2. xcode6 beta 中智能提示(自动完成)功能有时不显示的问题
  3. iOS实现类似于歌词进度效果
  4. githup上传代码
  5. # 20145210 《Java程序设计》第03周学习总结
  6. [转载]CentOS6.4+Mono3.0.7+Jexus5.2.5
  7. js页面加载进度条(这个就比较正式了,改改时间就完事儿)
  8. Laravel 安装指南
  9. 初识 BFC、 IFC、GFC、FFC
  10. 30. leetcode 121. Best Time to Buy and Sell Stock
  11. kmp——cogs 1570 乌力波
  12. Django 实现简单的文件上传
  13. IntelliJ IDEA 配置maven
  14. 重写(override)和重载(overload)的区别
  15. matlab画图命令笔记
  16. SpringBoot(10) Servlet3.0的注解:自定义原生Servlet、自定义原生Listener
  17. memtrack: Couldn&#39;t load memtrack module (No such file or directory) 的问题解决
  18. A+B for Input-Output Practice (VIII)
  19. jquery.cookie.js 删除cookie
  20. python如何帮我在投资中获取更高收益

热门文章

  1. 动态生成web表-asp.net table
  2. java基础知识疑难点
  3. NO.1: 视C++为一个语言联邦
  4. HDU 6158 笛卡尔定理+韦达定理
  5. Excel VBA 从外部工作簿取数的5种方法
  6. 第一节 Spring的环境搭建
  7. [整理]WebAPI中应用oData
  8. JavaScript继承详解(三)
  9. House Robber I &amp; II &amp; III
  10. MySQL多源复制【转】