#BS0000212. Đồ thị sắp xếp nổi bọt (Bubble Sort Graph)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đồ thị sắp xếp nổi bọt (Bubble Sort Graph)
Bubble Sort Graph
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Iahub starts with a permutation of the integers from to . The undirected graph initially has vertices labeled through and no edges.
During each bubble-sort pass, visit positions in order. Whenever , add an undirected edge between vertices labeled and , then swap these two elements. Repeat until a pass makes no swaps.
An independent set contains no pair of vertices connected by an edge. Determine the maximum size of an independent set in the resulting graph.
Input
The first line contains an integer . The second line contains integers , a permutation of .
Output
Print one integer: the maximum size of an independent set.
Subtasks
- Subtask 1 (20 points): ; for every ; all values are distinct.
- Subtask 2 (30 points): ; for every ; all values are distinct.
- Subtask 3 (50 points): ; for every ; all values are distinct.
Examples
Input
3
3 1 2
Output
2
Explanation
Swapping with adds edge ; swapping with adds . The permutation becomes . Vertices are nonadjacent, but adding would violate independence.
Input
4
4 3 2 1
Output
1
Explanation
Every pair begins in decreasing order and reverses its relative order during sorting, producing an edge. An independent set can contain only one vertex.