CF472C Design Tutorial: Make It Nondeterministic
题目描述
很多场合,名字是按姓的字典序排序的,但有的时候东方人和西方人姓名的顺序不一样,不知道哪个是姓,哪个是名,于是问题来了。给你n个人的姓名,每个姓名由两个字符串构成,有些姓在前,有的姓在后。现在给出这些人的排序,问这样的序列是否可能是这些名字的字典序排序。
输入格式
输入n
然后n行每行输入两个字符串。
最后一行输入一种n个数字的排列。
输出格式
如果可能是排列的顺序就输出YES,
否则输出NO。
### 数据规模和约定
1
说明/提示
In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.
In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.