当前位置:网站首页>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;
}
边栏推荐
- 微服务(Microservice)那点事儿
- Summary of week 22-07-02
- Hologres Query管理及超时处理
- 雅思考试流程、需要具体注意些什么、怎么复习?
- [ODX studio edit PDX] -0.3- how to delete / modify inherited elements in variant variants
- Is it safe to open and register new bonds? Is there any risk? Is it reliable?
- 基于三维gis平台的消防系统运用
- Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
- 快解析内网穿透帮助企业快速实现协同办公
- He worked as a foreign lead and paid off all the housing loans in a year
猜你喜欢

PMP证书续证流程

「运维有小邓」域密码策略强化器

Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)

Using the uniapp rich text editor

企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)

js如何实现数组转树

French scholars: the explicability of counter attack under optimal transmission theory

IT转测试岗,从迷茫到坚定我究竟付出了什么?

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

Significance of acrel EMS integrated energy efficiency platform in campus construction
随机推荐
Actual combat simulation │ JWT login authentication
Continuous modification of business scenario functions
Using the uniapp rich text editor
S32 design studio for arm 2.2 quick start
JS convert pseudo array to array
45 year old professor, she threw two super unicorns
[monitoring] ZABBIX
人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
Acrel-EMS综合能效平台在校园建设的意义
Financial markets, asset management and investment funds
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
【监控】zabbix
端口映射和端口转发区别是什么
How many triangles are there in the golden K-line diagram?
Introduction to ACM combination counting
How to avoid arc generation—— Aafd fault arc detector solves the problem for you
Parsing of XML
Upload avatar on uniapp
After Microsoft disables the IE browser, open the IE browser to flash back the solution
【雅思阅读】王希伟阅读P3(Heading)