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. 使用JS简单实现一下apply、call和bind方法

    使用JS简单实现一下apply.call和bind方法 1.方法介绍 apply.call和bind都是系统提供给我们的内置方法,每个函数都可以使用这三种方法,是因为apply.call和bind都实 ...

  2. python中time模块的调用及使用

    1 import time #通常import语句会写到代码的开头 2 3 print('------------------------') 4 print('------------------- ...

  3. Wireshark教程之统计功能

    实验目的 1.工具介绍 2.主要应用 实验原理 Wireshark的原名是Ethereal,新名字是2006年起用的.当时Ethereal的主要开发者Gerald决定离开他原来供职的公司NIS,并继续 ...

  4. 安装CentOS7出现dracut:/#……time解决办法

    当选择install CentOS7以后一会就会出现错误.报错信息:就是dracut:/# ... timeout一大堆.我本来以为是我的启动盘没做好,后来我又重做了好几次都是这问题. 解决 通过搜索 ...

  5. 关于Dll、Com组件、托管dll和非托管dll

    转自:https://blog.csdn.net/black_bad1993/article/details/53906252 Com组件 1.线程模型是干嘛用的?解决"多个线程" ...

  6. IComparer、IComparable、StringComparison枚举、CultureInfo 的用法

    IEnumerable<T> 和 IEnumerator<T>.泛型版本是新式代码的首要选项. InvariantCulture:程序间.程序数据库.程序网络交互用Invari ...

  7. Hadoop - 入门学习笔记(详细)

    目录 第1章 大数据概论 第2章 从Hadoop框架讨论大数据生态 第3章 Hadoop运行环境搭建(开发重点) 第4章 Hadoop运行模式 本地模式:默认配置 伪分布式模式:按照完全分布式模式配置 ...

  8. mysql设置定时任务-渐入佳境

    --作者:飞翔的小胖猪 --创建时间:2021年2月26日 前言 mysql中设置定时任务,需要先打开调度才能实现自动执行任务.调度功能开启后过再配合存储过程或事件等组件实现特定或定时的任务实现. 步 ...

  9. oj教程--坑

    1.OJ判断是只看输出结果的. 2.纯字符串用puts()输出. 3.有很多数学题是有规律的,直接推公式或用递归.循环. 4.擅用三目运算符 5.将乘法转换成加法减少时间 6.空间换时间 7.数组越界

  10. Pandas:DataFrame绘制并保存折线图时不打开图形只保存文件

    保存图形,用的是plt.savefig函数,只需要在保存图形之后,调用plt.close()关闭画布,就不会显示出来了: data.plot() outfile='image.png' plt.sav ...