题目链接: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. 关于海康威视与Unity3d集成冲突问题解决

    一.集成 1.1 了解什么是ANSI系列与GNU系列    https://baike.baidu.com/item/ANSI%20C/7657277?fr=aladdin    https://ww ...

  2. Xcode10.1 import头文件无法索引

    如下路径,修改设置 Xcode --> File --> Workspace Settings --> Build System --> Legacy Build System

  3. mysql distinct 用法详解及优化

    本事例实验用表task,结构如下 MySQL> desc task; +-------------+------------+------+-----+-------------------+- ...

  4. MySQL技术内幕读书笔记(二)——InnoDB存储引擎

    目录 InnoDB存储引擎 InnoDB存储架构 Checkpoint技术 Master Thread 工作方式 InnoDB关键特性(放一下,感觉看后面,再看总结吧) InnoDB存储引擎 Inno ...

  5. KADEMLIA算法

    一.概述 基于异或距离算法的分布式散列表(DHT), 实现了去中心化的信息存储于查询系统: Kademlia将网络设计为具有160层的二叉树,树最末端的每个叶子看作为节点,节点在树中的位置由同样是16 ...

  6. 【C++】C++中的分离式编译

    在C++中随着程序越来越复杂,我们希望把程序的各个部分分别储存在不同的文件中.C++支持的分离式编译(separate compilation)允许我们把程序分割到几个文件中去,每个文件独立编译. 头 ...

  7. 如何在IIS上发布网站 在阿里云服务器windows server2012r iis上部署.net网站

    如何在IIS上发布网站   本片博客记录一下怎么用IIS发布一个网站,以我自己电脑上一个已经开发完成的网站为例: 1.打开项目 这是我电脑上的一个项目,现在我记录一下将这个项目发布到iis上的整个过程 ...

  8. puppeteer新手遇到的坑

    puppeteer安装以及遇到的坑 1. 环境和安装 Puppeteer 至少需要 Node v6.4.0,如要使用 async / await,只有 Node v7.6.0 或更高版本才支持. no ...

  9. MySQL和Mongodb的区别与应用场景对比

    MySQL是关系型数据库 优势: 在不同的引擎上有不同 的存储方式. 查询语句是使用传统的sql语句,拥有较为成熟的体系,成熟度很高. 开源数据库的份额在不断增加,mysql的份额页在持续增长. 缺点 ...

  10. python 中有趣的库tqdm

    Tqdm 是 Python 进度条库,可以在 Python 长循环中添加一个进度提示信息用法:tqdm(iterator) # 方法1: import time from tqdm import tq ...