ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
F
Sherlock's bet to Moriarty
Codeforces
2800
原题
← EG →
翻译中…

Sherlock met Moriarty for a final battle of wits. He gave him a regular $*n*$ sided convex polygon. In addition to it, he gave him certain diagonals to form regions on the polygon. It was guaranteed that the diagonals did not intersect in interior points.

翻译中…

He took each of the region and calculated its importance value. Importance value for a region formed by vertices $*a*_{1}, *a*_{2}, ... , *a*_{*x*}$ of the polygon will be given by $2^{*a*_{1}} + 2^{*a*_{2}} + ... + 2^{*a*_{*x*}}$. Then, he sorted these regions on the basis of their importance value in ascending order. After that he assigned each region an index from $1$ to $*k*$, where $*k*$ is the number of regions, and index of region is its position in the sorted array calculated above.

翻译中…

He wants Moriarty to color the regions using not more than $20$ colors, such that two regions have same color only if all the simple paths between these two regions have at least one region with color value less than the color value assigned to these regions. Simple path between two regions $*f*$ and $*h*$ is a sequence of regions $*r*_{1}, *r*_{2}, ... *r*_{*t*}$ such that $*r*_{1} = *f*$, $*r*_{*t*} = *h*$, for each $1 ≤ *i* < *t*$ regions $*r*_{*i*}$ and $*r*_{*i* + 1}$ share an edge, and $*r*_{*i*} = *r*_{*j*}$ if and only if $*i* = *j*$.

翻译中…

Moriarty couldn't answer and asks Sherlock to solve it himself. Help Sherlock in doing so.

翻译中…

Input

翻译中…

First line contains two integers $*n*$ and $*m*$ ($3 ≤ *n* ≤ 100000$, $0 ≤ *m* ≤ *n* - 3$), the number of vertices in the polygon and the number of diagonals added.

翻译中…

Each of the next $*m*$ lines contains two integers $*a*$ and $*b*$ ($1 ≤ *a*, *b* ≤ *n*$), describing a diagonal between vertices $*a*$ and $*b*$. It is guaranteed that the diagonals are correct, i. e. $*a*$ and $*b*$ don't coincide and are not neighboring. It is guaranteed that the diagonals do not intersect.

翻译中…

Output

翻译中…

Let the number of regions be $*k*$.

翻译中…

Output $*k*$ space-separated integers, each between $1$ and $20$, representing the colors of the regions in the order of increasing importance.

翻译中…

If there are multiple answers, print any of them. It can be shown that at least one answer exists.

翻译中…

Note

翻译中…

In 2nd input, regions formed in order after sorting will be $(1, 2, 3)$, $(1, 3, 4)$, $(1, 4, 5)$, $(1, 5, 6)$, i.e, region $(1, 2, 3)$ is first region followed by region $(1, 3, 4)$ and so on.

翻译中…

So, we can color regions $1$ and $3$ with same color, as region number $2$ is on the path from $1$ to $3$ and it has color $1$ which is less than color of $1$ and $3$, i.e., color number $2$.

翻译中…

样例

Input #1
4 1
1 3
Output #1
1 2
InputCopy OutputCopy
Input #2
6 3
1 3
1 4
1 5
Output #2
2 1 2 3
InputCopy OutputCopy
题目信息
题号
776F
时间限制
2 s
内存限制
512 MB
标签
构造
数据结构
分治
计算几何
图论
模拟
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。