#C9165. Cyclical Permutation Check
Cyclical Permutation Check
Cyclical Permutation Check
You are given n integers. Your task is to determine whether a cyclical permutation of these integers can be formed such that the arrangement is valid under the following simple criterion:
A cyclical permutation is possible if and only if all the numbers are distinct. In other words, if every number appears exactly once, then output YES
; otherwise, output NO
.
Explanation:
- If the list contains unique numbers, then it is possible to arrange them in a circle without any repeated element next to each other.
- If any number is repeated, then a valid cyclical permutation cannot be formed.
This simple criterion is derived from the observation that for a cyclical permutation to be valid, every number's uniqueness is a necessary condition. Mathematically, if we let \( S \) be the set of given numbers and \( n \) be the total count, then a cyclical permutation exists if and only if \(|S| = n\).
inputFormat
The first line contains an integer (n) representing the number of integers. The second line contains (n) space-separated integers.
outputFormat
Output a single line: "YES" if a cyclical permutation can be formed (i.e., all numbers are unique), otherwise "NO".## sample
1
1
YES