A - Edge Checker 2 Editorial by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
Embedding
There are only \(14\) pairs of points that are directly connected by a segment. Thus, it is sufficient to check if the input is one of the \(14\).
Sample code 1 (Python)
a,b=map(int,input().split())
if (a,b)==(1,2) or (a,b)==(1,3) or\
(a,b)==(2,4) or (a,b)==(2,5) or\
(a,b)==(3,6) or (a,b)==(3,7) or\
(a,b)==(4,8) or (a,b)==(4,9) or\
(a,b)==(5,10) or (a,b)==(5,11) or\
(a,b)==(6,12) or (a,b)==(6,13) or\
(a,b)==(7,14) or (a,b)==(7,15):
print("Yes")
else:
print("No")
Sample code 2 (Python)
a,b=map(int,input().split())
if (a,b) in [(1,2),(1,3),(2,4),(2,5),(3,6),(3,7),\
(4,8),(4,9),(5,10),(5,11),(6,12),(6,13),(7,14),(7,15)]:
print("Yes")
else:
print("No")
Simpler solution
But such a solution is prone to an unexpected bug due to an oversight or typo, so it is a good idea to seek for a simpler solution.
In fact, in this problem, the answer is Yes
if and only if \(a=\left\lfloor\frac{b}{2}\right\rfloor\) (where \(\lfloor \cdot \rfloor\) denotes a flooring operation). Thus, it can be determined by the following simple if statement:
a,b=map(int,input().split())
if a==b//2:
print("Yes")
else:
print("No")
Bonus
As in this problem, a graph is a structure where the connectivity of points matter. A graph of the shape in this problem is called a perfect binary tree. A perfect binary tree with vertices indexed like that is commonly used in competitive programming. When you challenge a more difficult problem, keep in mind the property we used this time.
posted:
last update: