#include <iostream>
#include<cstdio>
#include<string.h>
using namespace std;
const int MAXN = 105;
int graph[MAXN][MAXN], indegree[MAXN], ans[MAXN];
int n;
void tuopu()
{
//计算入度
for(int i = 1; i<= n; i++)
for(int j = 1; j <= n; j++)
if(graph[i][j])
indegree[j]++;
for(int i = 1; i <= n; i++)
{
int k = 1;
while(indegree[k] != 0)
k++;
ans[i] = k;
indegree[k] = -1;
for(int j = 1; j <= n; j++)
{
if(graph[k][j]) indegree[j]--;//这里写为了if(graph[i][j])终于找到错误了
//cout<< indegree[j] << endl;
}
}
}
int main()
{
//freopen("input.txt", "r", stdin);
while(cin >> n)
{
memset(graph, 0, sizeof(graph)); //忘了memset函数结果就反悔了Runtime Error(ACCESS_VIOLATION)奇葩错误
memset(indegree, 0, sizeof(indegree));
memset(ans, 0, sizeof(ans));
int a;
for(int i = 1; i <= n; i++)
{
while(cin >> a && a)
graph[i][a] = 1;
}
tuopu();
for(int i =1; i < n ; i++)
cout << ans[i] << " ";
cout << ans[n] << endl;
}
return 0;
}
[NWPU][2014][TRN][16]图论拓扑排序 H - 基础
最新推荐文章于 2018-03-19 21:03:00 发布