当前位置:网站首页>[Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
[Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
2022-04-23 10:33:00 【Zimba_】
The question :
Given n n n A picture of a point , Yes m 1 m_{1} m1 There must be an edge , Yes m 2 m_{2} m2 This edge must not exist .
give Q Q Q Time to ask , Ask two points at a time x x x and y y y, ask :
- x x x Whether it must reach y y y
- x x x Is it possible to reach y y y
( n ≤ 1000 , Q ≤ 200000 ) (n\leq1000,Q\leq 200000) (n≤1000,Q≤200000)
practice :
The first idea to be clear is to build two maps , One has only certain edges , A sheet includes certain existing edges and possible edges .
Then the reachability between points is preprocessed for both graphs , Finally, ask directly .
One idea is the reachability of directed graphs , We use it S C C SCC SCC Find the strongly connected component , Then the shrinking point becomes D A G DAG DAG, And then you can do it .
But the idea of the problem solution seems to be better .
Directed graph we can use f l o y d floyd floyd stay o ( n 3 ) o(n^{3}) o(n3) Next, we deal with pairwise reachability , And then use b i t s e t bitset bitset Speed up , The final complexity is o ( n 3 / w ) o(n^{3}/w) o(n3/w), w w w by 64.
Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bitset<1001>f[1001],f1[1001];
int mpp[1005][1005];
int main()
{
int n,m1,m2,q;
scanf("%d%d%d%d",&n,&m1,&m2,&q);
for(int i=1;i<=m1;i++)
{
int a,b;
scanf("%d%d",&a,&b);
mpp[a][b]=1;
}
for(int i=1;i<=m2;i++)
{
int a,b;
scanf("%d%d",&a,&b);
mpp[a][b]=2;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)f[i][j]=f1[i][j]=1;
if(mpp[i][j]==1)
{
f[i][j]=1;
f1[i][j]=1;
}
else if(mpp[i][j]==0)
{
f1[i][j]=1;
}
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)if(f[i][k])
{
f[i]=f[i]|f[k];
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)if(f1[i][k])
{
f1[i]=f1[i]|f1[k];
}
}
while(q--)
{
int a,b;
scanf("%d%d",&a,&b);
if(f[a][b])printf("Yes ");
else printf("No ");
if(f1[a][b])printf("Yes\n");
else printf("No\n");
}
return 0;
}
版权声明
本文为[Zimba_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230621424686.html
边栏推荐
- Charles function introduction and use tutorial
- Chapter II in memory architecture (im-2.2)
- 景联文科技—专业数据标注公司和智能数据标注平台
- [provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
- C语言——自定义类型
- 1. Sum of two numbers (hash table)
- Examination questions and answers of the third batch (main person in charge) of Guangdong safety officer a certificate in 2022
- 【省选联考 2022 D2T1】卡牌(状态压缩 DP,FWT卷积)
- ansible playbook语法和格式 自动化云计算
- 0704、ansible----01
猜你喜欢

Arm debugging (1): two methods to redirect printf to serial port in keil

Comparison and practice of prototype design of knowledge service app

一文看懂 LSTM(Long Short-Term Memory)

lnmp的配置

Sim Api User Guide(4)

第120章 SQL函数 ROUND

Configuration of LNMP

Exercise questions and simulation test of refrigeration and air conditioning equipment operation test in 2022

/etc/shadow可以破解吗?

101. Symmetric Tree
随机推荐
Art template template engine
Solution architect's small bag - 5 types of architecture diagrams
Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file
Six practices of Windows operating system security attack and defense
Read LSTM (long short term memory)
CentOS/Linux安装MySQL
242. Valid Letter ectopic words (hash table)
微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
mysql同一个表中相同数据怎么合并
Installing MySQL with CentOS / Linux
997. Square of ordered array (array)
一文看懂 LSTM(Long Short-Term Memory)
ansible 云计算 自动化 命令行精简版
SQL Server cursor circular table data
IDEA——》每次启动都会Indexing或 scanning files to index
得到知识服务app原型设计比较与实践
SQL server query database deadlock
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
Image processing - Noise notes
997、有序数组的平方(数组)