hihoCoder - 1870 Jin Yong’s Wukong Ranking List (拓扑排序)(2018ICPC北京A)





Jin Yong was the most famous and popular Chinese wuxia (The one who fight bad people by his Wukong i.e. Wushu and Kongfu) novelist who lived in Hong Kong. Between 1955 and 1972, he wrote 14 novels which earned him a reputation as one of the greatest and most popular Chinese writers. Over 100 million copies of his works have been sold worldwide,not including a countless number of pirated copies. Jin Yong’s works seem to have magic. Once you begin to read a novel of his, you just can’t stop until you finish it.

Last month, Jin Yong passed away at the age of 94. Many Jin Yong’s fans in PKU held a meeting to memorize him. Jin Yong’s fans always like to discuss or argue or even quarrel about whose Wukong are better among the wuxia characters of his novel. During the meeting, this happened again:

Every fans said some words like "Qiao Feng's Wukong is better than Guo Jing's". Obviously, those words may contradict each other and then cause quarrels. As a boring and girlfriendless male programmer of EECS school, you always want to make some things. So you are eager to point out the contradictions as soon as possible. That means, you want to find out the first one whose words contradict the words said by others before him.

Please note that if A is better than B, and B is better than C, then of course A must be better than C.


There are no more than 15 test cases.

For each test case:

The first line is an integer n( 1 <= n <=20), meaning that there are n sentences.

The following n lines are those n sentences which is in the format below:

s1 s2

This means someone said that s1's Wukong was better than s2's. Both s1 and s2 are names of Jin Yong's characters which consists of only English letters. It's guaranteed that s1 and s2 are different, and their length is no more than 30. Names are case sensitive.


For each test case, print the first sentence which cause a contradiction. If there are no contradiction, print 0 instead.


DON'T try to figure out who are those names in the sample and waste your time.


BrokenReputation ExtinctNun
HelloLaught EnvelopeNotFlat
LandOverWind LonelyLight
FireMonk CutTheForest
CutTheForest LookCrazy
MakeFoxRush LetMeGo
HeroAunt UniqueLand
LookCrazy FireMonk


LookCrazy FireMonk




#define INF (0x3f3f3f3f)
using namespace std;
typedef long long int ll;
const int MAXN=10010;

map<string,int> mp;
int cnt=0;

vector<int> G[MAXN];

int degree[MAXN];

int deg[MAXN];

bool topo(){
    queue<int> que;
    for(int i=1;i<=cnt;i++){
    int num=0;
    for(int i=1;i<=cnt;i++){
        int tp=que.front();
        for(int i=0;i<G[tp].size();i++){
        return false;
    return true;

int main(){
    int N;
        for(int i=1;i<=2*N;i++){
        bool flag=0;
        for(int i=0;i<N;i++){
            string a,b;
                cout<<a<<" "<<b<<endl;
    return 0;


发布了402 篇原创文章 · 获赞 67 · 访问量 16万+

Ranking List


Description Background We knew something would be missing. We have just noticed that we do not have a tool helping us with the ranking list for this programming contest, and if we tried to create it by hand, you would probably end up waiting for the results until Sunday. So please help us out here, will you? Problem Your task is to write a program that determines the ranking list for a programming contest. You are given a list of the participating teams and a log file describing all the solutions submitted by the teams. The scoring of this programming contest is based on the following set of rules: The Contest Judges are solely responsible for determining the correctness of submitted runs. The winners of the Contest are determined by the Contest Judges and the Contest Director. The Contest Judges are empowered to adjust for or adjudicate unforeseen events and conditions. Teams will be ranked by the total number of correct solutions. For the purpose of awards, or in determining qualifier(s) for the ACM Contest, teams who solve the same number of problems are ranked by least total time. If this results in a draw situation the least number of attempts for each solved problems are taken into account. First the number of submissions for the problem with the most attempts are compared. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved. We are sure that you know all this. However, we think that the provisions of the second rule for resolving a draw situation are somewhat obscure, so that we do not want your program to implement such a procedure.Instead, if there is a draw situation of two or more teams with the same total number of correct solutions and the same total time, assign the same rank to these teams and list them in alphabetical order. Their relative ranking will be determined by the contest director, based on the number of attempts for each solved problems or the earliest problem solved. As we want the rank r of a team to indicate that r-1 teams did better, we need to adjust the numbers in a draw situation. If, for example, the two best teams' numbers of solved problems and total times coincide,they would both get rank 1, while the next team would be assigned rank 3. In this example, nobody would be assigned rank 2 by your program. We also have an addition to the third rule: There will be no penalty for incorrect solutions submitted after a correct solution was accepted from the same team. Input The first line contains the number of scenarios. For each scenario, you find the number n, 1 <= n <= 20, of teams in the first line and the (unique) names of the teams in the n following lines. A team name is a single word of length at most 8 containing letters and digits only, and for your convenience the teams are listed in alphabetical order. The next line contains the number k of problems and the number m of solutions that were submitted (1 <= k < 10, 0 <= m <= 2000). Each of the following m lines describes one such solution, in the format "problem time correctness team", where 1 <= problem <= k is the number of the problem,0 <= time < 300 is the number of minutes elapsed since the contest was started, correctness is either "Yes" or "No" and team is the name of the team that submitted the solution. You can assume that the lines in the log file are sorted by time. Output For each scenario print a ranking list containing every team that participated in the contest. The format is "rank. team solved time", where rank is the rank, team the name of the team, solved the number of correct solutions, and time the total time. In addition to the single blanks separating these four fields, make the table look nice by using a field width of 2 for the rank, 8 for the team's name, 1 for the number of problems solved and 4 for the total time (name left-adjusted, numbers right-adjusted, see sample output). Each scenario ends with a blank line. Sample Input 2 10 Team1 Team2 Team3 Team4 Team5 Team6 Team7 Team8 Team9 slowTeam 8 14 1 18 Yes Team4 1 57 Yes Team2 1 87 Yes Team3 1 101 Yes Team1 2 103 Yes Team5 2 120 Yes Team6 6 141 Yes Team7 1 147 No Team1 7 156 Yes Team2 5 167 Yes Team8 2 167 Yes Team9 5 170 No Team4 5 175 Yes Team4 1 234 No slowTeam 1 Team1 8 0 Sample Output 1. Team2 2 213 1. Team4 2 213 3. Team3 1 87 4. Team1 1 101 5. Team5 1 103 6. Team6 1 120 7. Team7 1 141 8. Team8 1 167 8. Team9 1 167 10. slowTeam 0 0 1. Team1 0 0 问答


©️2019 CSDN 皮肤主题: 点我我会动 设计师: 上身试试