Topic 1450: Generating Champions (topological sorting simple questions)

Source: Internet
Author: User

Title Link: http://ac.jobdu.com/problem.php?pid=1450

Detailed Links: https://github.com/zpfbuaa/JobduInCPlusPlus

Reference code:

////1450 produce the champion. CPP//Jobdu////Created by Pengfei_zheng on 21/04/2017.//copyright©2017 Pengfei_zheng. All rights reserved.//#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<cmath>#include<map>#defineMax_size 2017using namespacestd; Map<string,int>name2id;intIndegree[max_size];intN;intMain () { while(SCANF ("%d", &n)!=eof && n!=0){         for(inti =1; I <=2*n; i++) {Indegree[i]=0; }         while(!name2id.empty ()) name2id.clear (); stringA, B; intnum =0;  while(n--) {cin>>a>>b; if(!Name2id.count (a)) {num++;            Name2id.insert (Make_pair (A, num)); }            if(!Name2id.count (b)) {num++;            Name2id.insert (Make_pair (b, num)); }            intId_b =Name2id[b]; Indegree[id_b]++; }        intAns =0;  for(inti =1; I <= num; i++){            if(indegree[i]==0) ans++; } ans==1? printf"yes\n"): printf ("no\n"); }}/************************************************************** problem:1450 User:zpfbuaa language:c++ Re sult:accepted time:40 Ms memory:1536 kb****************************************************************/

Topic 1450: Generating Champions (topological sorting simple questions)

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.