HDU 1285 determine the tournament position

Source: Internet
Author: User

Determine the position of the match

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 19100 Accepted Submission (s): 7610


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

Authorsmallbeer (CML)

Source Hangzhou Electric ACM Training Team Training Tournament (VII)

Recommendlcy the topology of the graph, the topic requires the output of a small number of teams in front, can use the priority queue.
1#include <cstdio>2#include <vector>3#include <functional>4#include <queue>5 using namespacestd;6 BOOLcmpConst int&x,Const int&y)7 {8     returnX>y;9 }Ten  One Const intmaxn=550; Avector<int>V[MAXN]; - intINDEGREE[MAXN]; -priority_queue<int,vector<int>,greater<int> >Q; thequeue<int>s; - intMain () - { -     intn,m,a,b; +      while(SCANF ("%d%d", &n,&m) = =2) -     { +          for(intI=1; i<=n;i++) indegree[i]=0; A          for(intI=0; i<m;i++) at         { -scanf"%d%d",&a,&b); - V[a].push_back (b); -indegree[b]++; -         } -          for(intI=1; i<=n;i++) in             if(indegree[i]==0) Q.push (i); -          while(!q.empty ()) to         { +             intt=q.top (); Q.pop (); -              for(intI=0; I<v[t].size (); i++) the             { *indegree[v[t][i]]--; $                 if(indegree[v[t][i]]==0) Q.push (V[t][i]);Panax Notoginseng             } - S.push (t); the         } +         intfirst=true; A          while(!s.empty ()) the         { +             if(first) {printf ("%d", S.front ()); first=false;} -             Elseprintf"%d", S.front ()); $ S.pop (); $         } -printf"\ n"); -          for(intI=1; i<=n;i++) v[i].clear (); the     } -     Wuyi}

HDU 1285 determine 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.