P1 : Jin Yong’s Wukong Ranking List

Time Limit:1000ms
Case Time Limit:1000ms
Memory Limit:512MB

Description

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.

Input

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.

Output

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

Hint

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

Sample Input
2
BrokenReputation ExtinctNun
HelloLaught EnvelopeNotFlat
6
LandOverWind LonelyLight
FireMonk CutTheForest
CutTheForest LookCrazy
MakeFoxRush LetMeGo
HeroAunt UniqueLand
LookCrazy FireMonk
Sample Output
0
LookCrazy FireMonk

题意就是第一个人比第二个人厉害,问你从哪一句开始与上面的语句矛盾,闭包传递,有人是用dfs写的,有人是用floyd写的,我是用递归写的。

代码:

 //A-传递闭包-递归 or 有向图floyd
//看清楚题意,读错题了。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); string s[]; bool Find(string y,string x,int pos)
{
for(int i=;i<=pos;i+=){
if(s[i]==y){
if(s[i+]==x) return false;
else return Find(s[i+],x,pos);
}
}
return true;
} int main()
{
int n;
while(cin>>n){
for(int i=;i<=*n;i++)
cin>>s[i];
int flag=,pos;
for(int i=;i<=*n;i+=){
//cout<<Find(s[i+1],s[i],i-1)<<endl;
if(!Find(s[i+],s[i],i-)){
flag=;pos=i;break;
}
if(flag==) break;
}
if(flag==) cout<<s[pos]<<" "<<s[pos+]<<endl;
else cout<<<<endl;
}
}
*/ /*
5
b a
c d
d b
a b
b c a b
*/

最新文章

  1. 课堂 表单验证 JavaScript js
  2. MapGuide Maestro 5.1发布了
  3. struts2拦截器+监听器 .
  4. AJAX-----09iframe模拟ajax文件上传效果原理1
  5. Swift语言
  6. collections_python
  7. asp.net 使用 MongoDB 初体验
  8. Mysql优化相关总结
  9. sigaction 用法实例
  10. GTW likes math(简单数学)
  11. 网络性能测试工具Iperf/Jperf解读
  12. 如何在Windows系统下安装Linux虚拟机
  13. iOS 输入时键盘处理问题
  14. apache+php项目部署
  15. 201771010126 王燕《面向对象程序设计(java)》第十八周学习总结
  16. Submine Text3格式化HTML/CSS/JS代码
  17. C# 中集合类型需要按多个条件排序
  18. 【Unity】EasyTouch5触屏检测
  19. vue(ajax:axios中文文档)
  20. ACM数论之旅6---数论倒数,又称逆元(我整个人都倒了( ̄﹏ ̄))

热门文章

  1. 使用freemarker生成word、html时图片显示问题
  2. RotateAnimation 详解
  3. centos6.5 配置mongodb3
  4. 【Android】完善Android学习(五:API 3.2)
  5. [SCOI2009]生日礼物
  6. Spring Security 集成CAS实现单点登录
  7. JMeter 保持sessionId
  8. ssh 远程执行命令简介
  9. 要back的题目 先立一个flag
  10. 「6月雅礼集训 2017 Day11」tree