【LOJ】#2532. 「CQOI2018」社交网络
题解
基尔霍夫矩阵,外向树是入度矩阵-邻接矩阵
必须删掉第一行第一列然后再求行列式
代码
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define pdi pair<db, int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template <class T>
void read(T &res) {res = 0;char c = getchar();T f = 1;while (c < '0' || c > '9') {if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9') {res = res * 10 + c - '0';c = getchar();}res *= f;
}
template <class T>
void out(T x) {if (x < 0) {x = -x;putchar('-');}if (x >= 10) {out(x / 10);}putchar('0' + x % 10);
}
const int MOD = 10007;
int g[255][255], N, M;
int inc(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
int mul(int a, int b) { return 1LL * a * b % MOD; }
int fpow(int x, int c) {int res = 1, t = x;while (c) {if (c & 1) res = mul(res, t);t = mul(t, t);c >>= 1;}return res;
}
int determinant() {int res = 1;for (int i = 2; i <= N; ++i) {int l;for (l = i; l <= N; ++l) {if (g[l][i]) break;}if (l != i) {res = -res;for (int j = i; j <= N; ++j) swap(g[i][j], g[l][j]);}int inv = fpow(g[i][i], MOD - 2);for (int j = i + 1; j <= N; ++j) {int t = mul(g[j][i], inv);if (t) {for (int k = i; k <= N; ++k) {g[j][k] = inc(g[j][k], MOD - mul(t, g[i][k]));}}}}res = (res + MOD) % MOD;for (int i = 2; i <= N; ++i) {res = mul(res, g[i][i]);}return res;
}
void Solve() {read(N);read(M);int u, v;for (int i = 1; i <= M; ++i) {read(u);read(v);++g[u][u];--g[v][u];}for (int i = 1; i <= N; ++i) {for (int j = 1; j <= N; ++j) {g[i][j] = inc(g[i][j], MOD);}}out(determinant());enter;
}
int main() {
#ifdef ivorysifreopen("f1.in", "r", stdin);
#endifSolve();return 0;
}
转载于:https://www.cnblogs.com/ivorysi/p/10089348.html
【LOJ】#2532. 「CQOI2018」社交网络相关推荐
- Loj #3111. 「SDOI2019」染色
Loj #3111. 「SDOI2019」染色 题目描述 给定 \(2 \times n\) 的格点图.其中一些结点有着已知的颜色,其余的结点还没有被染色.一个合法的染色方案不允许相邻结点有相同的染色 ...
- Loj #3055. 「HNOI2019」JOJO
Loj #3055. 「HNOI2019」JOJO JOJO 的奇幻冒险是一部非常火的漫画.漫画中的男主角经常喜欢连续喊很多的「欧拉」或者「木大」. 为了防止字太多挡住漫画内容,现在打算在新的漫画中用 ...
- LOJ#2230. 「BJOI2014」大融合
LOJ#2230. 「BJOI2014」大融合 题目描述 小强要在$N$个孤立的星球上建立起一套通信系统.这套通信系统就是连接$N$个点的一个树.这个树的边是一条一条添加上去的. 在某个时刻,一条边的 ...
- loj#2143. 「SHOI2017」组合数问题
loj#2143. 「SHOI2017」组合数问题 题目描述 Solution 考虑转化一下我们要求的东西. ∑i=0n(nkik+r)=∑i=0n(nki)[i≡r(modk)]\sum_{i=0} ...
- LOJ#2542. 「PKUWC2018」随机游走
LOJ#2542. 「PKUWC2018」随机游走 题目描述 Solution 去过一个点集中所有节点的期望时间不好求,考虑min−maxmin-maxmin−max容斥,转化为求第一次到达某一个点集 ...
- LOJ#2145. 「SHOI2017」分手是祝愿
LOJ#2145. 「SHOI2017」分手是祝愿 题目描述 Solution 首先有一个结论: 灯的状态序列a1,a2...ana_1,a_2...a_na1,a2...an唯一对应了一个最优 ...
- Loj #2568. 「APIO2016」烟花表演
Loj #2568. 「APIO2016」烟花表演 题目描述 烟花表演是最引人注目的节日活动之一.在表演中,所有的烟花必须同时爆炸.为了确保安全,烟花被安置在远离开关的位置上,通过一些导火索与开关相连 ...
- Loj #2585. 「APIO2018」新家
Loj #2585. 「APIO2018」新家 题目描述 五福街是一条笔直的道路,这条道路可以看成一个数轴,街上每个建筑物的坐标都可以用一个整数来表示.小明是一位时光旅行者,他知道在这条街上,在过去现 ...
- Loj #2983. 「WC2019」数树
Loj #2983. 「WC2019」数树 题目背景 白兔喜欢树. 白云喜欢数数. 有 \(n\) 只鼠,白兔用 \(n − 1\) 根蓝色绳子把它们连成了一棵树,每根蓝色绳子连着两只鼠,白云用 \( ...
- Loj #2554. 「CTSC2018」青蕈领主
Loj #2554. 「CTSC2018」青蕈领主 题目描述 "也许,我的生命也已经如同风中残烛了吧."小绿如是说. 小绿同学因为微积分这门课,对"连续"这一概 ...
最新文章
- Windows下获取视频设备的一种改进实现
- things to do in English debate: scenario
- LAMP(linux下apache+mysql+php)平台编译安装的实现
- SpringMVC-获得Restful风格的参数
- 实战:使用IPSec保护服务器安全
- 在Google Cloud platform上创建Kubernetes cluster并使用
- kettle插入更新流程
- 4G DTU使用教程
- Spring Cloud Sleuth进阶实战
- iis7怎么安装php7,Linux下如何安装php7
- Python程序,辅助微信跳一跳游戏介绍
- VSCode运行Python教程
- Python访问PostGIS(建表、空间索引、分区表)
- html引入layer.js,require.js引用jquery、layer的简单实例用法
- 个盘子的汉诺塔需要移动几步_坨——理解递归实现quot;汉诺塔quot;代码的关键...
- ESP8266_APP连接试验
- swiper、vue-awsome-swiper插件使用
- 编写strcpy函数
- 谷歌地图下载器中地图艺术照
- WE大会马化腾要告诉我们什么?