HDU ACM 1285 determines the tournament position

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.