HDU 1285 determine the tournament position
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
Sample Output
Main topic: Chinese.
The idea of solving problems: simple topologies.
#include <stdio.h> #include <string.h>int gra[505][505], Degree[505];int main () {int n, m;while (scanf ("%d%d ", &n, &m) = = 2) {memset (GRA, 0, sizeof), memset (degree, 0, sizeof (degree)); for (int i = 0; I < m; i++) {int A, b;scanf ("%d%d", &a, &b), if (!gra[a][b]) {//judging heavy edge gra[a][b] = 1;degree[b]++;}} for (int i = 1; I <= n; i++) {//topology for (int j = 1; J <= N; j + +) {if (degree[j] = 0) {//Search for zero-in points as starting point degree[j]--;if ( I! = N) printf ("%d", j), Else printf ("%d\n", j); for (int k = 1; K <= N; k++) {//delete the Edge if (Gra[j][k]) associated with this point {degree[k]--;}} Break;}}}} return 0;}
HDU 1285 determining the tournament position (topological sorting)