Logo
(追記) (追記ここまで)

19915번 - Split the Attractions 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB213716533.505%

문제

There are $n$ attractions in Baku, numbered from 0ドル$ to $n-1$. There are also $m$ two-way roads, numbered from 0ドル$ to $m-1$. Each road connects two different attractions. It is possible to travel between any pair of attractions through the roads.

Fatima is planning to visit all of the attractions in three days. She already decided that she wants to visit $a$ attractions on the first day, $b$ attractions on the second day, and $c$ attractions on the third day. Therefore, she is going to partition the $n$ attractions into three sets $A,ドル $B,ドル and $C$ of sizes $a,ドル $b,ドル and $c,ドル respectively. Each attraction will belong to exactly one set, so $a + b + c = n$.

Fatima would like to find the sets $A,ドル $B,ドル and $C,ドル so that at least two out of the three sets are connected. A set $S$ of attractions is called connected if it is possible to travel between any pair of attractions in $S$ by using the roads and without passing through any attraction not in $S$. A partition of attractions into sets $A,ドル $B,ドル and $C$ is called valid if it satisfies the conditions described above.

Help Fatima find a valid partition of the attractions (given $a,ドル $b,ドル and $c$), or determine that no valid partition exists. If there are multiple valid partitions, you may find any of them.

구현

You should implement the following procedure:

int[] find_split(int n, int a, int b, int c, int[] p, int[] q)
  • $n$: the number of attractions.
  • $a,ドル $b,ドル and $c$: the desired sizes of sets $A,ドル $B,ドル and $C$.
  • $p$ and $q$: arrays of length $m,ドル containing the endpoints of the roads. For each $i$ (0ドル \leq i \leq m-1$), $p[i]$ and $q[i]$ are the two attractions connected by road $i$.
  • This procedure should return an array of length $n$. Denote the array by $s$. If there is no valid partition, $s$ should contain $n$ zeros. Otherwise, for 0ドル \leq i \leq n-1,ドル $s[i]$ should be one of 1ドル,ドル 2ドル,ドル or 3ドル$ to denote that attraction $i$ is assigned to set $A,ドル $B,ドル or $C,ドル respectively.

제한

  • 3ドル \leq n \leq 100,000円$
  • 2ドル \leq m \leq 200,000円$
  • 1ドル \leq a, b, c \leq n$
  • $a+b+c = n$
  • There is at most one road between each pair of attractions.
  • It is possible to travel between any pair of attractions through the roads.
  • 0ドル \leq p[i], q[i] \leq n-1$ and $p[i] \neq q[i]$ for 0ドル \leq i \leq m - 1$

예시 1

Consider the following call:

find_split(9, 4, 2, 3, [0, 0, 0, 0, 0, 0, 1, 3, 4, 5],
 [1, 2, 3, 4, 6, 8, 7, 7, 5, 6])

A possible correct solution is $[1, 1, 3, 1, 2, 2, 3, 1, 3]$. This solution describes the following partition: $A=\{0, 1, 3, 7\},ドル $B=\{4, 5\},ドル and $C=\{2, 6, 8\}$. The sets $A$ and $B$ are connected.

예시 2

Consider the following call:

find_split(6, 2, 2, 2, [0, 0, 0, 0, 0], [1, 2, 3, 4, 5])

No valid partition exists. Therefore, the only correct answer is $[0, 0, 0, 0, 0, 0]$.

서브태스크

번호배점제한
17

Each attraction is an endpoint of at most two roads.

211

$a = 1$

322

$m = n-1$

424

$n \leq 2500, m \leq 5000$

536

No additional constraints.

힌트

첨부

출처

Olympiad > International Olympiad in Informatics > IOI 2019 > Day 1 2번

  • 문제를 만든 사람: Alireza Farhadi, Saeed Seddighin

제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /