码迷,mamicode.com
首页 > 其他好文 > 详细

test

时间:2019-05-27 19:00:49      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:hellip   style   ogr   next   examples   cond   枚举   copy   least   

B. Pairs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Toad Ivan has mm pairs of integers, each integer is between 11 and nn, inclusive. The pairs are (a1,b1),(a2,b2),,(am,bm)(a1,b1),(a2,b2),…,(am,bm).

He asks you to check if there exist two integers xx and yy (1x<yn1≤x<y≤n) such that in each given pair at least one integer is equal to xx or yy.

Input

The first line contains two space-separated integers nn and mm (2n3000002≤n≤300000, 1m3000001≤m≤300000) — the upper bound on the values of integers in the pairs, and the number of given pairs.

The next mm lines contain two integers each, the ii-th of them contains two space-separated integers aiai and bibi (1ai,bin,aibi1≤ai,bi≤n,ai≠bi) — the integers in the ii-th pair.

Output

Output "YES" if there exist two integers xx and yy (1x<yn1≤x<y≤n) such that in each given pair at least one integer is equal to xx or yy. Otherwise, print "NO". You can print each letter in any case (upper or lower).

Examples
input
Copy
4 6
1 2
1 3
1 4
2 3
2 4
3 4
output
Copy
NO
input
Copy
5 4
1 2
2 3
3 4
4 5
output
Copy
YES
input
Copy
300000 5
1 2
1 2
1 2
1 2
1 2
output
Copy
YES
Note

In the first example, you can‘t choose any xx, yy because for each such pair you can find a given pair where both numbers are different from chosen integers.

In the second example, you can choose x=2x=2 and y=4y=4.

In the third example, you can choose x=1x=1 and y=2y=2.

题意:有m个数对(ai,bi),问是否存在两个数x,y使每个数对至少有一个数字=x或者=y

题解:通过枚举第一个数对中的数字可以确定后面的数字。即如果a1=x,那么把所有不含a1的数对存起来,判断数对中数字最多的数量是否=不含a1的数的总个数,同理可以枚举b1=x。

test

标签:hellip   style   ogr   next   examples   cond   枚举   copy   least   

原文地址:https://www.cnblogs.com/MekakuCityActor/p/10932328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!