CF736D Permutations(伴随矩阵)

Luogu

题解时间

首先把边直接放进邻接矩阵,

很明显行列式的奇偶和方案数的奇偶一样。

设 $ A_{ i , j } $ 为矩阵的该行列的余子式去掉一条边 $ x,y $ 后是否还为奇数等同于 $ A_{ x ,y } $ 是否为偶数。

至于如何快速求出所有余子式?

伴随矩阵

$ A^{ * } = ( A_{ i , j } )^{T} $ ,T代表转置。

有结论 $ A^{ * } = A^{ -1 } | A | $ ,在此不作证明。

然后直接求逆就完事,用bitset优化 $ O(\frac{ n^{ 3 } }{ w }) $ 。

#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
struct pat{int x,y;pat(int x=0,int y=0):x(x),y(y){}bool operator<(const pat &p)const{return x==p.x?y<p.y:x<p.x;}};
template<typename TP>inline void read(TP &tar)
{
TP ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){ret=ret*10+(ch-'0');ch=getchar();}
tar=ret*f;
}
template<typename TP,typename... Args>inline void read(TP& t,Args&... args){read(t),read(args...);}
namespace RKK
{
const int N=2011,M=500011;
int n,m;
bitset<N<<1> a[N];
int ex[M],ey[M];
void gauss()
{
for(int l=1;l<=n;l++)
{
int e=0;for(int i=l;i<=n;i++)if(a[i][l]){e=i;break;}
if(!e) return (void)(cerr<<"WDNMD"<<endl);
if(e&&e!=l) swap(a[e],a[l]);
for(int i=1;i<=n;i++)if(i!=l&&a[i][l]) a[i]^=a[l];
}
}
int main()
{
read(n,m);
for(int i=1;i<=m;i++) read(ex[i],ey[i]),a[ex[i]][ey[i]]=1;
for(int i=1;i<=n;i++) a[i][n+i]=1;
gauss();for(int i=1;i<=m;i++) puts(a[ey[i]][n+ex[i]]?"NO":"YES");
return 0;
}
}
int main(){return RKK::main();}

CF736D Permutations(伴随矩阵)的更多相关文章

  1. 题解 CF736D Permutations

    link Description 现在,你有一个二分图,点数为 \(2n\). 已知这个二分图的完备匹配的个数是奇数. 现在你要知道,删除每条边后,完备匹配个数是奇数还是偶数. \(1\le n\le ...

  2. 【CF736D】Permutations 线性代数+高斯消元

    [CF736D]Permutations 题意:有一个未知长度为n的排列和m个条件,第i个条件$(a_i,b_i)$表示第$a_i$个位置上的数可以为$b_i$.保证最终合法的排列的个数是奇数.现在有 ...

  3. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  4. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  5. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  6. POJ2369 Permutations(置换的周期)

    链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  7. Permutations

    Permutations Given a collection of distinct numbers, return all possible permutations. For example,[ ...

  8. 【leetcode】Permutations

    题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the ...

  9. [leetcode] 47. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

随机推荐

  1. Solution -「AT 3913」XOR Tree

    \(\mathcal{Description}\)   Link.   给定一棵树,边 \((u,v)\) 有边权 \(w(u,v)\).每次操作可以使一条简单路径上的边权异或任意非负整数.求最少的操 ...

  2. 第8章 File I/O,File类操作文件的属性

    1.文件 1.1.什么是文件? 答:文件可认为是相关记录或放在一起的数据的集合 1.2.文件- -般存储在哪里? 答: 磁盘,硬盘,文件夹 1.3.JAVA程序如何访向文件属性? JAVA API:i ...

  3. 阿里云服务器ECS挂载数据盘—linux系统

    参考阿里云官网帮助文档:https://help.aliyun.com/document_detail/25426.html 里面有些步骤说的不是很清楚,初学者可能操作时会遇到问题.通过这篇文档进行进 ...

  4. .netrar最不安全几个问题总结

    任何有经历的.NET开发人员都知道,即使.NET应用程序具有废物收回器,内存走漏一直会发作. 并不是说废物收回器有bug,而是咱们有多种办法能够(轻松地)导致保管语言的内存走漏. 内存走漏是一个偷偷摸 ...

  5. FPGA+x86构建高性能国产网络测试仪竞技之道

    众所周知,以太网已经深入我们的生活无处不在,企业.校园.大数据中心和家庭等都离不开网络,否则我们的生活将受到严重的影响. 以太网的接口速率也是迅速发展:10M.100M.GE.10GE.40GE.10 ...

  6. Docker学习笔记(详细)

    目录 01 介绍 02 Docker安装 03 Docker常用命令 04 Docker镜像 05 Docker容器数据卷 06 Dockerfile解析 Dockerfile构建过程解析 Docke ...

  7. 如何在 Spring Boot 优雅关闭加入一些自定义机制

    个人创作公约:本人声明创作的所有文章皆为自己原创,如果有参考任何文章的地方,会标注出来,如果有疏漏,欢迎大家批判.如果大家发现网上有抄袭本文章的,欢迎举报,并且积极向这个 github 仓库 提交 i ...

  8. ❀ Spring5学习大总结

    一.了解 Spring 基本介绍.主要思想 IoC/DI 1.了解 Spring 基本介绍 (1) Spring是什么? Spring 是一个轻量级的 DI/IoC 和 AOP 容器的开源框架,致力于 ...

  9. linux多进/线程编程(1)—— 基础概念(PCB、MMU、进程状态)

    学习大概就是不断迭代.重构的过程,不复习的学习是不负责任的,亦是无用的. 本系列博客主要作为个人记录,主要是贴图和代码,不做详细解释,以后有时间可能会重写:从下一篇开始上代码,代码可以运行是对自己的最 ...

  10. k8s-coredns 介绍和部署

    1.k8s-coredns 实现了集群内部通过服务名进行可以访问.添加服务后,会自动添加一条解析记录 cat /etc/resolv.conf nameserver 10.0.0.2 search k ...