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. [iOS Xcode注释插件]

    来自onevcat的VVDocumenter-Xcode,地址是:https://github.com/onevcat/VVDocumenter-Xcode 使用方式:按三下"/" ...

  2. ArrayList用法

    ArrayList属于collection->List接口下的一个集合类 针对数组的一些缺陷,集合框架提供了ArrayList集合类,对数组进行封装,实现了长度可变的数组,而且和数组彩用相同的存 ...

  3. PhyLab2.0需求与功能分析改进文档(NABCD)

    PhyLab1.0需求规格说明文档 1. 概述 1.1 项目概述 软剑攻城队小组于2015学年开发了PhyLab物理实验网站,一经发布好评如潮.网站的核心功能是提供预习报告和自动数据处理,而后加入了论 ...

  4. RBAC权限设计

    http://blog.csdn.net/ms_x0828/article/details/7035956 RBAC 模型作为目前最为广泛接受的权限模型 角色访问控制(RBAC)引入了Role的概念, ...

  5. Yocto开发笔记之《Tip-应用程序无法在目标机运行》(QQ交流群:519230208)

    官方app编译环境编译的应用程序可以在开发板自带的系统中运行,自己编译并烧写了系统,却提示: root@imx6ulevk:/root# ./VTTerminal -sh: ./VTTerminal: ...

  6. 利用POI 技术动态替换word模板内容

    项目中需要实现一个功能,动态替换给定模板里面的内容,生成word文档提供下载功能. 中间解决了问题有: 1.页眉的文档logo图片解决,刚开始的时候,HWPFDocument 对象无法读取图片对象(已 ...

  7. uC/OS-II内存(OS_mem)块

    /*************************************************************************************************** ...

  8. CodeForces 689B Mike and Shortcuts (BFS or 最短路)

    题目链接:http://codeforces.com/problemset/problem/689/B 题目大意: 留坑 明天中秋~

  9. thinkphp新增

    $m = M('content'); //与   $m = new Model('content')效果一样 $date = array( 'username' => I('username', ...

  10. js搜索输入关键词

    function getInput(val,a){ var id = 'ser-key'; if(a=='focus'){ document.getElementById(id).value=''; ...