Determine the position of the match, it is very simple topological sort. The collar matrix representation.
#include <iostream> using namespace Std;int map[501][501];int degree[501];int main () {int I,j,k;int n,m, P1,p2;bool F;while (cin>>n>>m) {memset (map,0,sizeof (map)); memset (degree,0,sizeof (degree)); for (i=1;i <=m;i++) {cin>>p1>>p2;if (!MAP[P1][P2]) //To judge a heavy edge, otherwise error {map[p1][p2]=1;degree[p2]++;}} f=0; Topology sort for (i=1;i<=n;i++) //n processing to process all points {for (j=1;j<=n;j++)//Find 0 Points {if (degree[j]==0) {degree[j]--; Decrease the corresponding degree to avoid the next processing if (f==0) {cout<<j;f=1;} else cout<< "" <<j;for (k=1;k<=n;k++)//Remove the edge connected to a point with a degree of 0, i.e. reading minus one if (map[j][k]==1) degree[k]--; Break;}}} Cout<<endl;} return 0; }
HDU ACM 1285 determines the tournament position