Boardgame Expo

시간 제한2초메모리 제한2048 MB

요약
친구 관계 그래프에서 각 구간이 연결 부분 그래프를 이루도록 줄을 최소 개수의 연속한 구간으로 나누고, 그 크기들을 출력한다.
난이도

어려움10점 중 8점

유형
그래프, 그리디, 투 포인터, 유니온 파인드
정답자
아직 제출이 없습니다

문제

Every year, a big Boardgame Expo takes place in Cluj-Napoca, showcasing a wide selection of new games. The main attraction this year is a game called BoardOina.

There are nn players lined up in a queue, waiting to try out the game. Players are numbered from 00 to n−1n − 1 in their order in the queue. Player 00 is at the front of the queue and player n−1n − 1 is at the back.

There are mm distinct friendship relations between mm pairs of players in the queue. Specifically, for each ii from 00 to m−1m − 1, inclusive, player x\[i]x\[i] and player y\[i]y\[i] are friends, where 0≤x\[i]<y\[i]<n0 ≤ x\[i] < y\[i] < n. Friendship relations are symmetric.

Consider a sequence of kk consecutive players in the queue starting at player ss (for any ss and kk such that 0≤s<n0 ≤ s < n and 1≤k≤n−s1 ≤ k ≤ n − s). This sequence of players forms a friend group of size kk if for all pairs of two players, they are connected by a sequence of friendship relations within that friend group. Specifically, players s,s+1,…,s+k−1s, s + 1, \dots , s + k − 1 form a friend group of size kk if, for each uu and vv such that s≤u<v<s+ks ≤ u < v < s + k, there exists a sequence of players p\[0],…,p\[l−1]p\[0], \dots , p\[l − 1] such that:

  • l≥2l ≥ 2;
  • s≤p\[j]<s+ks ≤ p\[j] < s + k for each jj from 00 to l−1l − 1, inclusive;
  • p\[0]=up\[0] = u and p\[l−1]=vp\[l − 1] = v;
  • players p\[j]p\[j] and p\[j+1]p\[j + 1] are friends for each jj from 00 to l−2l − 2, inclusive.

Note that in the case of k=1k = 1, player ss alone forms a friend group of size 11.

BoardOina can be played by any number of players. However, to make the game more successful, the organizers only let friend groups play it.

Only one group can play at a time. For each game, a friend group starting at the player at the front of the queue is formed, and starts playing the game. The players in this friend group are removed from the queue. This process is repeated until the queue becomes empty. Formally, we say that the queue can be partitioned into gg friend groups if there exists an array of group sizes, K=\[K\[0],K\[1],…,K\[g−1]]K = \[K\[0],K\[1], \dots ,K\[g − 1]], such that each of the following conditions holds.

  • g>0g > 0 and K\[j]>0K\[j] > 0 (for each jj such that 0≤j<g0 ≤ j < g);
  • K\[0]+K\[1]+⋯+K\[g−1]=nK\[0] + K\[1] + \dots + K\[g − 1] = n;
  • for each jj between 00 and g−1g − 1, inclusive, players s\[j],s\[j]+1,…,s\[j]+K\[j]−1s\[j], s\[j] + 1, \dots , s\[j] + K\[j] − 1 form a friend group of size K\[j]K\[j], where s\[0]=0s\[0] = 0 and otherwise s\[j]=K\[0]+K\[1]+⋯+K\[j−1]s\[j] = K\[0] + K\[1] + \dots + K\[j − 1].

The organizers want to minimize the number of friend groups that play the game. That is, they want to partition the queue into gg friend groups such that it is not possible to partition the queue into g−1g − 1 (or less) friend groups.

Your task is to find a partitioning of the queue into a minimum number of friend groups, and report the array of group sizes.

제한

  • 2≤n≤100,0002 ≤ n ≤ 100\\, 000
  • 0≤m≤200,0000 ≤ m ≤ 200\\, 000
  • 0≤x\[i]<y\[i]<n0 ≤ x\[i] < y\[i] < n (for each ii such that 0≤i<m0 ≤ i < m)
  • Friendship relations are distinct. In other words, x\[i]≠x\[j]x\[i] \ne x\[j] or y\[i]≠y\[j]y\[i] \ne y\[j] (for each ii and jj such that 0≤i<j<m0 ≤ i < j < m).
  • If there are multiple solutions with minimum number of groups, you can return any valid solution.

예제

이 문제는 공개된 예제가 없습니다.