Codeforces Round #270 1003

C. Design Tutorial: Make It Nondeterministic

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.

Let's try to make a new task. Firstly we will use the following task. There are n people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are n people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation p?

More formally, if we denote the handle of the i-th person as hi, then the following condition must hold:

.

Input

The first line contains an integer n(1 ≤ n ≤ 105) — the number of people.

The next n lines each contains two strings. The i-th line contains strings fi and si(1 ≤ |fi|, |si| ≤ 50) — the first name and last name of the i-th person. Each string consists only of lowercase English letters. All of the given 2n strings will be distinct.

The next line contains n distinct integers: p1, p2, ..., pn(1 ≤ pi ≤ n).

Output

If it is possible, output "YES", otherwise output "NO".

Sample test(s)

Input


gennady korotkevich 
petr mitrichev 
gaoyuan chen 
1 2 3

Output

NO

Input


gennady korotkevich 
petr mitrichev 
gaoyuan chen 
3 1 2

Output

YES

 
pair的用法,sort按first排序
名姓分别存,排序后从前往后扫存在可行能扫到底每个人都被扫到。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int n;
pair<string,int> mp[]; int main()
{
scanf("%d",&n);
for(int i = ;i<=(n<<);i++)
{
cin>>mp[i].first;
mp[i].second = (i+)/;
}
sort(mp+,mp+*n+);
int rk;
int j = ;
int ct = ;
for(int i = ;i<=n;i++)
{
scanf("%d",&rk);
for(;j<=*n;j++)
{
if(mp[j].second==rk)
{
ct++;
break;
}
}
}
if(ct==n) puts("YES");
else puts("NO");
return ;
}

Codeforces Round #270 1003的更多相关文章

  1. Codeforces Round #270 1002

    Codeforces Round #270 1002 B. Design Tutorial: Learn from Life time limit per test 1 second memory l ...

  2. Codeforces Round #270 1001

    Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...

  3. Codeforces Round #270 A~D

    Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...

  4. Codeforces Round #270(利用prim算法)

    D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...

  5. codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)

    题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...

  6. 多种方法过Codeforces Round #270的A题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))

    题目链接:http://codeforces.com/contest/472/problem/A 题目: 题意:哥德巴赫猜想是:一个大于2的素数一定可以表示为两个素数的和.此题则是将其修改为:一个大于 ...

  7. Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS

    题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...

  8. Codeforces Round #270 D C B A

    谈论最激烈的莫过于D题了! 看过的两种做法不得不ORZ,特别第二种,简直神一样!!!!! 1th:构造最小生成树. 我们提取所有的边出来按边排序,因为每次我们知道边的权值>0, 之后每次把边加入 ...

  9. Codeforces Round #270

    A 题意:给出一个数n,求满足a+b=n,且a+b均为合数的a,b 方法一:可以直接枚举i,n-i,判断a,n-i是否为合数 #include<iostream> #include< ...

随机推荐

  1. VS2010生成安装包

    项目的第一个版本出来了,要做个安装包,之前没有做过,网上看看贴,写了一个,总结下,根据本项目的需要,没有写的太复杂,可能还不是很完善,仅作参考. 首先在打开 VS2010    >   文件 & ...

  2. [iOS OpenCV的使用,灰度和二值化]

    看网上方法很多,但版本都不够新,我看了网上一些知识,总结了下,来个最新版Xcode6.1的. 最近主要想做iOS端的车牌识别,所以开始了解OpenCV.有兴趣的可以跟我交流下哈. 一.Opencv的使 ...

  3. kali linux 2.0安装sublime text 2

    第一种方法:Download the Sublime Text 2 & Extract it:32位:$ wget http://c758482.r82.cf2.rackcdn.com/Sub ...

  4. Docker探索系列1之docker入门安装与操作

    preface docker这种时髦的技术我接触的比较晚,如果不是公司在使用这项技术,估计还得会更晚接触.好了,说下我司现在docker使用的情况.docker在我司是用来跑web服务的,里面的web ...

  5. BZOJ2827: 千山鸟飞绝

    离散化坐标,每个坐标开一棵以鸟的编号为关键字的平衡树.每次插入时打2个标记,同时更新自身.这个方法比较显然,而且好写.正解好像用很迷的方法乱搞了一波,然后用线段树不打标记就做出来了,并不会. trea ...

  6. B450黑苹果之路(1)

    安装黑苹果,采取的是懒人版写入磁盘分区中,然后再安装1)从硬盘中分两个区,一个是未来使用的目标分区,一个是磁盘镜像区2)由于HFS+支持逻辑分区,所以两个分区都放逻辑分区上,分区不格式化3)使用硬盘助 ...

  7. 闭包->类的实例数组排序

    简单的字符串数组排序就一句话 Arr.sort(function(s1,s2){return s1.localeCompare(s2));//升序 Arr.sort(function(s1,s2){r ...

  8. git push to nas

    1 建nas目录 在nas的/volume1/git_repos目录下新建相关的目录,并在该目录下运行git init --bare cd /volume1/git_repos mkdir wifi_ ...

  9. vim 使用总结

    VIM分屏显示   1 . 水平分屏split(sp) || 垂直分屏vsplit(vs) :(v)split 输入这样的命令后vi就会将当前的窗口平分为两个,并且在这两个窗口中显示的是同一篇文章.如 ...

  10. Java/JavaWeb中读取资源文件

    1.一般工程中使用I/O类指定文件的绝对路径读取 FileInputStream fis = new FileInputStream("src/main/resources/zsm.prop ...