Description
There are N teams (1<=n<=500), numbered three-in-one, .... , N to play, after the game, the Referee Committee will be all the teams from the arrival of the ranking, but now the referee committee can not directly get each team's performance, only know the results of each game, that is, P1 win P2, with P1,p2 said, ranked P1 before P2. Now ask you to compile the program to determine the rankings.
Input
The input has several groups, the first behavior in each group is two number n (1<=n<=500), M, where n represents the number of troops, and m indicates the input data for the M row. In the next M-row data, there are also two integers per line p1,p2 means that the P1 team won the P2 team.
Output
Give a ranking that meets the requirements. There is a space between the queue numbers at the time of the output, and no space after the last.
Other Notes: Qualifying rankings may not be unique, at which point the output is required to be numbered in front of the team; the input data is guaranteed to be correct, i.e. the input data ensures that there must be a qualifying ranking.
Sample Input
4 31 22) 34 3
Sample Output
1 2 4 3
#include <iostream>#include<cstring>#include<cstdio>using namespacestd;Const intn=510;intI,j,k,m,n;intMap[n][n],indegre[n];voidtopo () { for(i=1; i<=n;i++) for(j=1; j<=n;j++) { if(indegre[j]==0) {Indegre[j]--; After outputting this point, row this pointif(i!=n) cout<<j<<" "; Elsecout<<j<<Endl; for(k=1; k<=n;k++)//stroke The line between the opponent who won the match {if(map[j][k]==1) Indegre[k]--; } Break; } }}intMain () {intp,q; while(SCANF ("%d%d", &n,&m)! =EOF) {memset (map,0,sizeof(map)); memset (Indegre,0,sizeof(Indegre)); for(i=0; i<m;i++) {scanf ("%d%d",&p,&q); if(!Map[p][q]) {Map[p][q]=1; Q lost to the number of opponents indegre[q] Indegre[q]++; }} topo (); } return 0;}
Topology sequencing (1)