当前位置:网站首页>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;
}
边栏推荐
- 人生无常,大肠包小肠, 这次真的可以回家看媳妇去了。。。
- Basic points of the game setup of the points mall
- [monitoring] ZABBIX
- 股票账户佣金怎么调低,炒股佣金怎么调低网上开户安全吗
- 电力运维云平台:开启电力系统“无人值班、少人值守”新模式
- Actual combat simulation │ JWT login authentication
- Acrel-EMS综合能效平台在校园建设的意义
- OSEK standard ISO_ 17356 summary introduction
- IT转测试岗,从迷茫到坚定我究竟付出了什么?
- [path planning] RRT adds dynamic model for trajectory planning
猜你喜欢
PMP certificate renewal process
Combien de temps faut - il pour obtenir un certificat PMP?
快解析内网穿透帮助企业快速实现协同办公
Application of fire fighting system based on 3D GIS platform
ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
如何避免电弧产生?—— AAFD故障电弧探测器为您解决
How to apply for PMP project management certification examination?
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
随机推荐
Chinese verification of JS regular expressions (turn)
Significance of acrel EMS integrated energy efficiency platform in campus construction
JS how to realize array to tree
Tester's algorithm interview question - find mode
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
He worked as a foreign lead and paid off all the housing loans in a year
Enterprise application business scenarios, function addition and modification of C source code
Go step on the pit - no required module provides package: go mod file not found in current directory or any parent
用快解析内网穿透实现零成本自建网站
【路径规划】RRT增加动力模型进行轨迹规划
Advanced template
Using fast parsing intranet penetration to realize zero cost self built website
The pit of sizeof operator in C language
取得PMP证书需要多长时间?
Jar batch management gadget
[IELTS reading] Wang Xiwei reading P4 (matching1)
Is it safe to open an account in the College of Finance and economics? How to open an account?
How to effectively monitor the DC column head cabinet
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
Jar批量管理小工具