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