当前位置:网站首页>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;
}
边栏推荐
- [paper reading] Tun det: a novel network for meridian ultra sound nodule detection
- ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
- 业务实现-日志写到同一个行数据里面
- [ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
- JS 将伪数组转换成数组
- 基本放大电路的学习
- 微服务(Microservice)那点事儿
- ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
- [IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
- 企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
猜你喜欢
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
[IELTS reading] Wang Xiwei reading P3 (heading)
Hash table, hash function, bloom filter, consistency hash
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
Solution record of jamming when using CAD to move bricks in high configuration notebook
同事的接口文档我每次看着就头大,毛病多多。。。
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
PMP certificate renewal process
Combien de temps faut - il pour obtenir un certificat PMP?
随机推荐
端口映射和端口转发区别是什么
Pytoch --- use pytoch to realize linknet for semantic segmentation
取得PMP证书需要多长时间?
S32 design studio for arm 2.2 quick start
Jar批量管理小工具
OpenHarmony资源管理详解
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
Cross domain request
快解析——好用的内网安全软件
Consolidated expression C case simple variable operation
[path planning] RRT adds dynamic model for trajectory planning
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
[JS] - [dynamic planning] - Notes
Chinese verification of JS regular expressions (turn)
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
Instructions for go defer
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
Selected cutting-edge technical articles of Bi Ren Academy of science and technology