1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
:
(1)(0).
(2),.
(3),.
*/
bool TopologicalSort(int a[][101]){ //True
    int n = a[0][0], i, j;
    int into[101], ans[101];
    memset(into, 0, sizeof(into));
    memset(ans, 0, sizeof(ans));
    for (i = 1; i <= n; i++){
        for (j = 1; j <= n; j++){
            if (a[i][j] > 0)
            into[j]++;//
        }
    }
    into[0] = 1;
    for (i = 1; i <= n; i++){
        j = 0;
        while (into[j] != 0){
            j++;              //0j
            if (j > n)
                return false;
        }
        ans[i] = j;           //j
        into[j] = -1;          //j-1
        for (int k = 1; k <= n; k++){
            if (a[j][k] > 0)
            into[k]--;         //j
        }
    }
    for (i = 1; i <= n; i++){
        cout << ans[i] << " "; //
    }
    cout << endl;
    return true;
}