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. 自动同步bing壁纸

    在百度搜东西,经常出来一大坨广告:要么就是复制粘贴文章.完全没有创新,搜索越来越困难.偶尔用一下bing还挺好用. bing的壁纸是真心好看,每天不重样.决定写个脚本同步一下它的壁纸. 一.以我的Wi ...

  2. nginx域名转发

    场景1:因服务器限制,所以只对外开放了一个端口,但是需要请求不同的外网环境,所以在中转服务器上用nginx做了一次转发 实现: server { listen 8051; server_name lo ...

  3. [ME]不知道第几次学c语言,仍觉得水深莫测

    首先声明这篇东西是个人的碎碎念,没有任何干货. 接下c语言课助教的活儿时还没什么感觉,快要开学了,才感觉到紧张,逼着自己开始看老师发来的课件,说是查错,其实算是自己再好好学一遍,免得到时候面对同学们的 ...

  4. MLD协议测试——网络测试仪实操

    一.简介 1. MLD简介 MLD · Multicast Listener Discovery Protocol · 组播侦听者发现协议 功能 · 在终端主机和与其直接相邻的组播路由器之间建立/维护 ...

  5. 数据分析刚入门?这几个BI软件你一定得知道!

    在当前乃至未来5年的职场中,将取代你的可能不是 AI ,而是比你"更懂"数据分析的同事.毕竟,现在做什么都讲究"用数字说话",很多岗位在招聘JD中均给出了&qu ...

  6. C# Semaphore 信号量 锁 简单理解

    信号量(Semaphore) Semaphore 一般译作 信号量,它也是一种线程同步工具,主要用于多个线程对共享资源进行并行操作的一种工具类.它代表了一种许可的概念,是否允许多线程对同一资源进行操作 ...

  7. 【C#IO 操作】字符流(StreamWriter、StreamReader)

    StreamWaiter类和StreamReader类的用法 事实上, StreamReader为了性能的考虑, 在自己的内部内置并维护了一个byte buffer. 如果在声明StreamReade ...

  8. Linux系统最重要的工具——Shell学习笔记

    一.为什么学习Shell脚本语言 1.Shell脚本语言是实现Linux/UNIX系统管理及自动化运维必备的重要工具,Linux/UNIX系统底层及 基础应用软件的核心大都涉及Shell脚本的内容. ...

  9. Activity跳转显式方法及隐式方法

    1 public class AActivity extends AppCompatActivity { 2 private Button btnJump; 3 @Override 4 protect ...

  10. layui模板注册表单

    今天晚上用layui模板做了一个简单的注册表单,功能主要有可以js验证密码重复,可以验证手机号码. 这是界面 下面是我的html文件代码 <!DOCTYPE html> <html ...