当前位置:网站首页>Acwing164. Accessibility Statistics (topological sorting +bitset)
Acwing164. Accessibility Statistics (topological sorting +bitset)
2022-07-05 00:05:00 【eva_ can(not)survive】
164. Accessibility Statistics - AcWing Question bank High quality algorithm question bank https://www.acwing.com/problem/content/166/ For the first time bitset What a magical container , It is very convenient for us to calculate subsets .
This question also directly shows that there is a DAG So we can find the topological sequence directly , Then traverse in reverse order and record the states that can be reached at each point .
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
using P = pair<int, int>;
int ver[MAXN];
int head[MAXN];
int nxt[MAXN];
int cnt;
int in[MAXN];
int tuop[MAXN];
int cnt1;
void add(int x, int y) {
ver[++cnt] = y;
nxt[cnt] = head[x];
head[x] = cnt;
in[y]++;
}
int n, m;
const int N = 3e4 + 5;
bitset<N> rec[N];
void topsort() {
queue<int> q;
map<int, int> mp;
for (int i = 1; i <= n; i++) {
if (in[i])
continue;
q.push(i);
}
while (!q.empty()) {
int t = q.front();
q.pop();
tuop[++cnt1] = t;
for (int i = head[t]; i; i = nxt[i]) {
int v = ver[i];
in[v]--;
if (!in[v])
q.push(v);
}
}
}
int main() {
scanf("%d %d", &n, &m);
int x, y;
for (int i = 1; i <= m; i++) {
scanf("%d %d", &x, &y);
add(x, y);
}
topsort();
for (int i = n; i >= 1; i--) {
int j = tuop[i];
rec[j][j] = 1;
for (int k = head[j]; k; k = nxt[k]) {
int v = ver[k];
rec[j] |= rec[v];
}
}
for (int i = 1; i <= n; i++) {
printf("%d\n", rec[i].count());
}
return 0;
}
边栏推荐
- 快解析内网穿透帮助企业快速实现协同办公
- Introduction to ACM combination counting
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- 取得PMP证书需要多长时间?
- 【雅思阅读】王希伟阅读P4(matching1)
- Is it safe to open an account in the College of Finance and economics? How to open an account?
- How to save your code works quickly to better protect your labor achievements
- How many triangles are there in the golden K-line diagram?
- Fast analysis -- easy to use intranet security software
- Parsing of XML
猜你喜欢

多回路仪表在基站“转改直”方面的应用

MIT-6.824-lab4B-2022(万字思路讲解-代码构建)

Tester's algorithm interview question - find mode
![P3304 [SDOI2013]直径(树的直径)](/img/5c/984675bf4517481f80f54657c6c7ad.png)
P3304 [SDOI2013]直径(树的直径)

图解网络:什么是网关负载均衡协议GLBP?

How to apply for PMP project management certification examination?

【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)

Selected cutting-edge technical articles of Bi Ren Academy of science and technology

华为200万年薪聘请数据治理专家!背后的千亿市场值得关注

人脸识别5- insight-face-paddle-代码实战笔记
随机推荐
Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
The input of uniapp is invalid except for numbers
Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
Is it safe to open and register new bonds? Is there any risk? Is it reliable?
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
Actual combat simulation │ JWT login authentication
Microservice
如何用快解析自制IoT云平台
[IELTS reading] Wang Xiwei reading P4 (matching1)
What is the difference between port mapping and port forwarding
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
js正则表达式之中文验证(转)
[JS] - [dynamic planning] - Notes
模板的进阶
Illustrated network: what is gateway load balancing protocol GLBP?
A new method for analyzing the trend chart of London Silver
【雅思阅读】王希伟阅读P4(matching1)
Business implementation - the log is written to the same row of data
Expand your kubecl function