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. 理解Faster R-CNN

    首先放R-CNN的原理图 显然R-CNN的整过过程大致上划分为四步: 1.输入图片 2.生成候选窗口 3.对局部窗口进行特征提取(CNN) 4.分类(Classify regions) 而R-CNN的 ...

  2. Solution -「CF 1622F」Quadratic Set

    \(\mathscr{Description}\)   Link.   求 \(S\subseteq\{1,2,\dots,n\}\),使得 \(\prod_{i\in S}i\) 是完全平方数,并最 ...

  3. Solution Set -「ARC 107」

    「ARC 107A」Simple Math   Link.   答案为: \[\frac{a(a+1)\cdot b(b+1)\cdot c(c+1)}{8} \] 「ARC 107B」Quadrup ...

  4. CoRR 2015 | MXNet: A Flexible and Efficient Machine Learning Library for Heterogeneous Distributed Systems

    MXNet是一个支持多种编程语言的机器学习库,使用MXNet可以方便地实现机器学习算法,尤其是深度神经网络.通过嵌入在宿主语言中,它将声明式符号表达与命令式张量计算相结合.它提供自动求导以计算梯度.M ...

  5. FreeHttp2.3升级说明

    一.升级方法 下载新版本插件 https://files.cnblogs.com/files/lulianqi/FreeHttp2.3.0zip  或 http://lulianqi.com/file ...

  6. RSA公私钥生成与使用

    参考 KeyStore 简述 Keytool 简述 Certificate Chain (证书链) 简述 详解RSA加密算法

  7. v-model的修饰符

    .lazy 就是在用户输入时数据不会进行传输,在失去焦点后或者按回车,才会将数据将进行改变 .number 因为v-model所绑定的数据,都会默认转换为string类型,而.number就能将数据转 ...

  8. Devops 开发运维高级篇之容器管理

    Devops 开发运维高级篇之容器管理 安装docker Dockerfile镜像脚本入门制作 Harbor镜像仓库安装及使用 不过多解释docker直接秀基操 安装docker:(jenkins服务 ...

  9. Renix签名字段详解——网络测试仪实操

    一.签名字段简介 在添加/修改流量时,会有一个签名字段选项 (1)勾选以后,RENIX软件在发流时,会把每个报文的Payload(净荷)的最后18字节修改为特殊的值,用来统计流的时延.丢包等内容 (2 ...

  10. 『无为则无心』Python基础 — 62、Python中自定义迭代器

    目录 1.迭代器对象的创建 2.实际应用案例 3.总结: 1.迭代器对象的创建 迭代器是一种可以被遍历的对象,并且能够作用于next()函数,迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问 ...