当前位置:网站首页>[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
边栏推荐
- Sim Api User Guide(4)
- 242、有效字母异位词(哈希表)
- 209. Subarray with the smallest length (array)
- JUC concurrent programming 07 -- is fair lock really fair (source code analysis)
- Ansible cloud computing automation command line compact version
- Installing MySQL with CentOS / Linux
- Arm debugging (1): two methods to redirect printf to serial port in keil
- mysql同一个表中相同数据怎么合并
- Detailed explanation of MapReduce calculation process
- 精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
猜你喜欢
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
101. Symmetric Tree
SQL Server recursive query of superior and subordinate
Sim Api User Guide(5)
Net start MySQL MySQL service is starting MySQL service failed to start. The service did not report any errors.
Operation of 2022 tea artist (primary) test question simulation test platform
Sim Api User Guide(4)
Windows installs redis and sets the redis service to start automatically
Sim Api User Guide(6)
Comparison and practice of prototype design of knowledge service app
随机推荐
域名和IP地址的联系
Six practices of Windows operating system security attack and defense
MapReduce compression
Turn: Maugham: reading is a portable refuge
LeetCode-608. Tree node
SSH uses private key to connect to server without key
Installing MySQL with CentOS / Linux
C language - custom type
How can swagger2 custom parameter annotations not be displayed
Deploy jar package
微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件
CSP certification 202203-2 travel plan (multiple solutions)
转:毛姆:阅读是一座随身携带的避难所
SQL Server recursive query of superior and subordinate
Using multithreading to output abc10 times in sequence
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
Juc并发编程09——Condition实现源码分析
997、有序数组的平方(数组)
Detailed explanation of MapReduce calculation process
59. Spiral matrix (array)