Hangzhou Electric 1285--To determine the competition ranking (topological sorting)

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): 17184 Accepted Submission (s): 6827


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 3 1 2 2 3 4 3

Sample OUTPUT1 2 4 3

Authorsmallbeer (CML)

SOURCE Hangzhou Electric ACM Training Team Training Tournament (VII)

Recommendlcy | We have carefully selected several similar problems for you:2647 3342 1811 1548 1269 data less available adjacency matrix;
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 intmap[550][550], indegree[550], result[550];6 intN, M;7 voidTsort () {8     intM, k =0;9      for(inti =0; I < n; i++){Ten         //*m =-1; One          for(intj =1; J <= N; J + +){ A             if(!Indegree[j]) { -m = j; Break; -             } the         }     -result[k++] = m; indegree[m]--;//delete point; +          for(intj =1; J <= N; J + +)//Delete Edge; -             if(Map[m][j]) +--Indegree[j]; A     }  at      for(inti =0; I < K; i++){ -         if(I! =0) -printf"%d", Result[i]); -         Else -printf"%d", Result[i]); -     } inprintf"\ n"); - } to intMain () + { -      while(~SCANF ("%d%d", &n, &m)) the     { *memset (Map,0,sizeof(map)); $memset (Indegree,0,sizeof(Indegree));Panax Notoginseng          for(inti =0; I < m; i++) -         { the             intA, B; +scanf"%d%d", &a, &b); A             if(!map[a][b]) {//go heavy; theMAP[A][B] =1;  +indegree[b]++; -             } $         } $ Tsort (); -     } -     return 0; the}

Hangzhou Electric 1285--To determine the competition ranking (topological sorting)

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.