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