C++ 拓扑排序算法实现:蒜头君的互粉游戏人气指数计算
#include
using namespace std;
const int N = 1010;
int n, m;
int in_degree[N], fans[N], follow[N];
vector
void topo_sort() {
queue
int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[b].push_back(a); in_degree[a]++; follow[a]++; } topo_sort(); for (int i = 0; i < n; i++) { cout << fans[i] - follow[i] << endl; } return 0; }
原文地址: https://www.cveoy.top/t/topic/nP6f 著作权归作者所有。请勿转载和采集!