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)