417B - Crash - CodeForces Solution


implementation *1400

Please click on ads to support us..

Python Code:

import sys
from math import *
from collections import Counter
input=sys.stdin.readline

def isSorted(a):
    for i in range(1, len(a)):
        if a[i] < a[i-1]:
            return False
    return True

d={}
n=int(input())
for i in range(n):
    a,b=map(int,input().split())
    a,b=b,a
        if a in d:
        if b in d[a]:
            continue
        elif b-1 in d[a]:
            d[a].add(b)
        else:
            print("NO")
            exit()
    if not a in d:
        if b==0:
            d[a]=set([b])
        else:
            print("NO")
            exit()
print("YES")

        


Comments

Submit
0 Comments
More Questions

1372A - Omkar and Completion
159D - Palindrome pairs
981B - Businessmen Problems
1668A - Direction Change
1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards
897A - Scarborough Fair
1433B - Yet Another Bookshelf
1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND