Determine the position of the match
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 35253 Accepted Submission (s): 13787
Problem description has 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 inputs have several groups, the first behavior in each group is two n (1<=n<=500), M, where n represents the number of troops, and m represents 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 gives 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 Input4 31 22 34 3
Sample OUTPUT1 2 4 3 topological ordering is a non-topological ordering of the non-aligned graphs and the forward graphs with loops. Topological ordering of a direction-free graph G is to arrange all the points in G into a linear sequence so that any one of the vertices in the graph can have an edge <u,v> in the graph of any of them, and then you appear before v in a linear sequence. The linear sequence produced by topological ordering of a forward graph is called a sequence that satisfies the topological sort order, or the topological sort for short. A direction-free graph can usually represent an action sequence or scheme, whereas a topological sequence with a non-circular graph is usually expressed as a feasible scheme. Find the zero-degree point, enter the stack, and delete its associated edges. Repeat the operation until all points are found
#include <iostream>#include<string>#include<algorithm>#include<Set>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#defineEach (i,n) (int i=1;i<= (n); ++i)using namespacestd;inthead[100004],rudu[100004];structnode{intTo,next;} bian[100004];inttop=0;intqueu[100004];voidAddintAintb) {bian[top].to=b; Bian[top].next=Head[a]; Head[a]=top++;}intMain () {intn,m; while(~SCANF ("%d%d",&n,&m)) {intb; memset (Head,-1,sizeof(head)); memset (Rudu,0,sizeof(Rudu)); for(intI=0; i<m;i++) {cin>>a>>b; Add (A, b); RUDU[B]++; } intC=0; while(c<N) { for(intI=1; i<=n;i++) { if(rudu[i]==0) {Queu[c++]=i; Rudu[i]=-1; for(intj=head[i];j!=-1; j=bian[j].next) rudu[bian[j].to]--; Break; } } } for(intI=0; i<c;i++) {printf (i==c-1?"%d\n":"%d", Queu[i]); } } return 0;}
HDU-1285 Simple Topology Ordering