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. C#位操作与枚举的应用

    看到代码里有用位操作来判断条件的,以前没有这么用过,做个笔记: int add = 2; int modify = 4; int delete = 8; Console.WriteLine((add ...

  2. Why TestNG?

    最近计划将工程中的单元测试从JUnit迁移到TestNG上面. Why TestNG(http://kaczanowscy.pl/tomek/sites/default/files/testng_vs ...

  3. CF 321B Kefa and Company(贪心)

    题目链接: 传送门 Kefa and Company time limit per test:2 second     memory limit per test:256 megabytes Desc ...

  4. Alpha版本十天冲刺——Day 2

    站立式会议 会议总结 队员 今天完成 遇到的问题 明天要做 感想 鲍亮 学习post请求连接服务器,学习git 无 http资源请求方法封装,完成Android验证码获取接口和登录验证接口 今天满课, ...

  5. Beta版本冲刺第一天 12.5

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 前段时间完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 对Alpha版本的分析总结,学习新技术,对Beta版本的讨论规 ...

  6. HTML5学习总结-01 开发环境和历史

    1 搭建HTML5开发环境 1 安装一款支持HTML5的浏览器 FireFox, Chrome 2 开发工具 SublineText, Eclipse, HBuilder, WebStorm 注:使用 ...

  7. python regrex

    Python正则表达式指南 The source from the website http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.htm ...

  8. css012 css布局简介

    css012  css布局简介 一.    网页布局的类型 网页布局的类型 1.固定宽度 2.流式 3.相应式web设计 二.    如何进行css布局 1.强大的<div>标签 网页的h ...

  9. C#------各种常见错误解决方法

    1.错误:模型生成过程中检测到一个或多个验证错误 表示实体中的数据列没有和SQLServer数据库里面的表中的数据列完全相同,比如SQLServer中有ID,Name,Post,那么实体中也应该有ID ...

  10. 使用node的插件UglifyJs来合并和压缩文件

    code: var fs = require('fs'); var jsp = require("./UglifyJS-master/uglify-js").parser; var ...