题目链接:https://codeforces.com/contest/1090/problem/D

Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "greater", "less", or "equal".

After several years, he has found the first sheet of paper, but he couldn't find the second one. Also he doesn't remember the array he had. In particular, he doesn't remember if the array had equal elements. He has told this sad story to his informatics teacher Dr Helen.

She told him that it could be the case that even if Vasya finds his second sheet, he would still not be able to find out whether the array had two equal elements.

Now Vasya wants to find two arrays of integers, each of length n. All elements of the first array must be distinct, and there must be two equal elements in the second array. For each pair of positions Vasya wrote at the first sheet of paper, the result of the comparison must be the same for the corresponding elements of the first array, and the corresponding elements of the second array.

Help Vasya find two such arrays of length n, or find out that there are no such arrays for his sets of pairs.

Input
The first line of input contains two integers n, m — the number of elements in the array and number of comparisons made by Vasya (1≤n≤100000, 0≤m≤100000).

Each of the following m lines contains two integers ai, bi — the positions of the i-th comparison (1≤ai,bi≤n; ai≠bi). It's guaranteed that any unordered pair is given in the input at most once.

Output
The first line of output must contain "YES" if there exist two arrays, such that the results of comparisons would be the same, and all numbers in the first one are distinct, and the second one contains two equal numbers. Otherwise it must contain "NO".

If the arrays exist, the second line must contain the array of distinct integers, the third line must contain the array, that contains at least one pair of equal elements. Elements of the arrays must be integers from 1 to n.

Examples
input
1 0
output
NO
input
3 1
1 2
output
YES
1 3 2
1 3 1
input
4 3
1 2
1 3
2 4
output
YES
1 3 4 2
1 3 4 1

题意:

给定 $n,m$,给定 $m$ 个无序对 $(a,b)$ 代表位置 $a$ 上的数字和位置 $b$ 上的数字进行比较。且这 $m$ 个无序对无重复。

让你寻找两个序列,第一个序列由 $1 \sim n$ 组成,元素互不相同且唯一。第二个序列,要满足和第一个序列对于 $m$ 个比较的结果相同,且某一个数字要出现两次,其余则皆属于 $[1,n]$ 且互不相同且唯一。

题解:

可以想见,如果有 $\frac{n(n-1)}{2}$ 次比较,那么就可以唯一确定该序列,则要输出 "NO" 。

一旦少那么一次,就代表有两个位置上的数字没有比较,不妨令这两个位置上的数字原本是最大和次大,现在全变成最大,这样不会改变 $m$ 次比较的结果。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e5+;
int n,m;
pii p[maxn];
pii findpos()
{
int a,b,c=;
pii res;
for(a=;a<=n;a++) for(b=a+;b<=n;b++) if((res=make_pair(a,b))!=p[++c]) return res;
}
int main()
{
cin>>n>>m;
for(int i=,a,b;i<=m;i++)
{
scanf("%d%d",&a,&b);
p[i]=make_pair(min(a,b),max(a,b));
}
if((ll)n*(n-)/ <= (ll)m) {printf("NO\n");return ;} printf("YES\n");
sort(p+,p++m);
pii pos=findpos();
for(int i=,cnt=;i<=n;i++)
{
if(i==pos.first) printf("%d ",n-);
else if(i==pos.second) printf("%d ",n);
else printf("%d ",++cnt);
}
printf("\n");
for(int i=,cnt=;i<=n;i++)
{
if(i==pos.first) printf("%d ",n);
else if(i==pos.second) printf("%d ",n);
else printf("%d ",++cnt);
}
printf("\n");
}

Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]的更多相关文章

  1. Codeforces 1090A - Company Merging - [签到水题][2018-2019 Russia Open High School Programming Contest Problem A]

    题目链接:https://codeforces.com/contest/1090/problem/A A conglomerate consists of n companies. To make m ...

  2. Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]

    题目链接:https://codeforces.com/contest/1090/problem/M There are n houses along the road where Anya live ...

  3. Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]

    题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...

  4. Codeforces 1491G - Switch and Flip(构造题)

    Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \( ...

  5. Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)

    传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...

  6. Codeforces 362D Fools and Foolproof Roads 构造题

    题目链接:点击打开链接 题意: 给定n个点 m条边的无向图 须要在图里添加p条边 使得图最后连通分量数为q 问是否可行,不可行输出NO 可行输出YES,并输出加入的p条边. set走起.. #incl ...

  7. 集训第四周(高效算法设计)P题 (构造题)

    Description   There are N<tex2html_verbatim_mark> marbles, which are labeled 1, 2,..., N<te ...

  8. 集训第四周(高效算法设计)O题 (构造题)

    A permutation on the integers from 1 to n is, simply put, a particular rearrangement of these intege ...

  9. Codeforces Gym100952 D. Time to go back-杨辉三角处理组合数 (2015 HIAST Collegiate Programming Contest)

    D. Time to go back   time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. 每天一个linux命令(11):nl命令

    1.命令简介 nl (Number of Lines) 将指定的文件添加行号标注后写到标准输出.如果不指定文件或指定文件为"-" ,程序将从标准输入读取数据. 2.用法 nl [选 ...

  2. spring+springmvc+ibatis整合注解方式实例

    需求说明 实现用户通过数据库验证登录需求.採用 Myeclipse+Tomcat 6.0+Mysql 5.0+JDK 1.6 2.数据库表 开发所用是Mysql数据库,仅仅建立单张用户表T_USER, ...

  3. failed to create process怎么解决

    python 在cmd时,报错:failed to create process怎么解决 在cmd命令前加 : python -m 命令(如:python -m conda update conda)

  4. 【转】33 个 2017 年必须了解的 iOS 开源库

    1.IGListKit,作者是Instagram Engineering Instagram 程序员做的,IGListKit 是数据驱动的 UICollectionView 框架,为了构建快速和可扩展 ...

  5. NBU将RAC数据库恢复到单机

    恢复的过程和(https://www.cnblogs.com/abclife/p/5687993.html)差不多.但是,具体过程有些不同.如果按照之前的恢复方式,在run语句中同时运行restore ...

  6. Apache Spark as a Compiler: Joining a Billion Rows per Second on a Laptop(中英双语)

    文章标题 Apache Spark as a Compiler: Joining a Billion Rows per Second on a Laptop Deep dive into the ne ...

  7. [rook] rook的控制流

    以下是rook为一个pod准备可用块存储的过程: 1. rook operator运行,并且在k8s每台机器上运行一个rook agent的pod: 2. 用户创建一个pvc,并指定storagecl ...

  8. Istio究竟是干嘛的?

    要聊ServiceMesh,就不得不提Istio,它是ServiceMesh目前最流行的实践, 当微服务架构体系越来越复杂的时候,需要将“业务服务”和“基础设施”解耦,将一个微服务进程一分为二: 一个 ...

  9. 我们为什么要在Android中使用RxJava

    本文翻译来自–>Why should we use RxJava on Android 另外: 微凉一季 再另外: 微凉一季 感觉RxJava近期风生水起,不学习一下都不好意思了.洒家也是初学R ...

  10. opcache分享

    opcache的技术分享ppt,独家唯一经过自己实验的分享 https://pan.baidu.com/s/1-73-QHOSeet7tcR81gto6Q