Tournaments-Simple topological sequencing

Source: Internet
Author: User

This is my favorite red. NiceTest Instructions: Number of groups in the first line of test cases the number of fighters in each set of cases and the number of matches in the contest if you cannot determine the unique ranking, output no Answer and the slag code is attached below .
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <iostream>5#include <algorithm>6#include <queue>7#include <vector>8#include <Set>9#include <stack>Ten#include <string> One#include <sstream> A#include <map> -#include <cctype> - using namespacestd; the inta[ -][ -],n,m,visited[ -],result[ -]; - voidTopsort ()//There's a unique sequence - { -     intmark=0, flag,fuck=1; +      for(intI=1; i<=n;i++)//start with the first place . -     { +mark=0; A          for(intj=0; j<n;j++)//To start looking for these men . at         { -             if(visited[j]==0)//No, Dad . -             { -Flag=j;//This doesn't have a father . -mark++; -             } in         } -         if(mark!=1)//1:mark=0 is a father, Ring 2: There are two no father, the base of to         { +fuck=0; -printf"No Answer"); the              Break; *         } $Result[i]=flag;//first place, save it.Panax Notoginsengvisited[flag]--;//the first one owes a father (who has been used) -          for(intk=0; k<n;k++) the         { +             if(A[k][flag])//The Father who did not have a father just now (that is, no grandfather), the father died, the son's pro-dad-1 A             { thevisited[k]--; +             } -         } $     } $     if(Fuck) -          for(intI=1; i<=n;i++) -printf"%c", result[i]+'A'); theprintf"\ n"); - }Wuyi intMain () the { -     intT; Wuscanf"%d",&t); -      while(t--) About     { $scanf"%d%d",&n,&m); -Memset (visited,0,sizeof(visited)); -Memset (A,0,sizeof(a)); -          for(intI=0; i<m;i++) A         { +             Charb,c; thescanf"%c%c",&b,&c); -             if(a[c-'A'][b-'A']==0)//Direct prevention of heavy edges//since the output from the high end $             { thea[c-'A'][b-'A']=1;//C has a dad called B. thevisited[c-'A']++;//C's Papa number + + the             } the         } - Topsort (); in     } the}

Tournaments-Simple topological sequencing

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.