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 -「NOI 2021」「洛谷 P7740」机器人游戏

    \(\mathcal{Description}\)   Link.   自己去读题面叭~ \(\mathcal{Solution}\)   首先,参悟[样例解释 #2].一种暴力的思路即为钦定集合 \ ...

  2. Solution -「AGC 019F」「AT 2705」Yes or No

    \(\mathcal{Description}\)   Link.   有 \(n+m\) 个问题,其中 \(n\) 个答案为 yes,\(m\) 个答案为 no.每次你需要回答一个问题,然后得知这个 ...

  3. MySQL架构原理之体系架构

    MySQL是最流行的关系型数据库软件之一,由于其体量小.速度快.开源免费.简单易用.维护成本低等,在季军架构中易于扩展.高可用等优势,深受开发者和企业的欢迎,在互联网行业广泛使用. 其系统架构如下: ...

  4. BGP4协议测试——信而泰网络测试仪实操

    文章关键词 BGP:路由测试:协议测试:矢量路由协议: 一.前言: BGP是自治系统外部路由协议,用来在AS之间传递路由信息 路径矢量路由协议,从设计上避免了环路的发生 其路由信息中携带了所经过的全部 ...

  5. 这个数据分析工具秒杀Excel,可视化分析神器!

    ​入门Excel容易,想要精通就很难了,大部分人通过学习能掌握60%的基础操作,但是一些复杂数据可视化分析就需要用到各种技巧,操作理解难度加深 Excel作为一直是使用最广泛的数据表格工具,在数据量日 ...

  6. Vim的强大配置文件(一键配置)

    转:https://blog.csdn.net/u010871058/article/details/54253774/ 花了很长时间整理的,感觉用起来很方便,共享一下. 我的vim配置主要有以下优点 ...

  7. Pandas:从CSV中读取一个含有datetime类型的DataFrame、单项时间数据获取

    前言 有一个CSV文件test.csv,其中有一列是datetime类型,其他列是数值列,就像下边这样: 问题 1.读取该CSV文件,把datetime列转换为datetime类型,并将它设置为索引列 ...

  8. js数组 把竖向数组排列为横向数组

    项目中会遇到为了渲染方便要把后台给的竖向数组排列为横向数组 例:后台传回的数组为[2004, 2005, 2006, 2007, 2008] [46890000, 55900500, 33786400 ...

  9. 面向对象编程(C++篇1)——引言

    目录 1. 概述 2. 详论 2.1. 类与对象 2.2. 数据类型 3. 目录 1. 概述 现代C++与最原始的版本已经差不多是两种不同的语言了.不断发展的C++标准给C++这门语言带来了更多的范式 ...

  10. go泛型教程

    泛型 原文 在线阅读 导读: 约束 使用方法 实现原理 跟其它语言的泛型进行对比 用例子学泛型 issues 泛型需满足 go1.18+ 约束 go使用interface作为约束,约束的意思是约束了这 ...