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

28221번 - Cyberland 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
7 초 1024 MB202342016.260%

문제

The year 3742 has arrived, and now it is Cyberland's turn to host the APIO. In this world, there are $N$ countries indexed from 0ドル$ to $N - 1,ドル along with $M$ bidirectional roads (allowing travel in both directions) indexed from 0ドル$ to $M - 1$. The $i$-th road (0ドル ≤ i < M$) connects two different countries, $x[i]$ and $y[i],ドル and requires a certain amount of time $c[i]$ to pass the road. All participants have gathered in Cyberland for the APIO, except for your country. You are living in country 0ドル,ドル and Cyberland is country $H$. As the cleverest person in your country, your assistance is urgently needed once again. To be more specific, you are asked to determine the minimum time required to reach Cyberland from your country.

Some countries can clear your total passing time. Also, some countries can divide your total passing time by 2ドル$ (divide-by-2ドル$ ability). You can visit a country repeatedly. Every time you visit a country, you may choose whether to use the special ability in the country. But you can use the special ability at most once in a single visit (which means that special ability can be used multiple times by visiting the country multiple times). Moreover, you can only use the divide-by-2ドル$ ability at most $K$ times in case of being caught by Cyberland Chemistry Foundation. Once you reached Cyberland, you cannot move anywhere because the great APIO contest will be held soon.

An array $arr$ is given, where $arr_i$ (0ドル ≤ i < N$) shows the special abilities of country $i$. There are 3ドル$ types of special abilities:

  • $arr_i = 0,ドル means this country makes the passing time 0ドル$.
  • $arr_i = 1,ドル means the passing time remains unchanged at this country.
  • $arr_i = 2,ドル means this country divides the passing time by 2ドル$.

It is guaranteed that $arr_0 = arr_H = 1$ holds. In other words, Cyberland and your country do not have any special abilities.

Your country does not want to miss any moment of APIO, so you need to find the minimum time to reach Cyberland. If you cannot reach to Cyberland, your answer should be $-1$.

구현

You need to implement the following function:

double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr);
  • $N$: The number of countries.
  • $M$: The number of bidirectional roads.
  • $K$: The limit of divide-by-2ドル$ ability usage.
  • $H$: The index of the country Cyberland.
  • $x,ドル $y,ドル $c$: three arrays with a length of $M$. the tuple $(x[i], y[i], c[i])$ represents the $i$-th undirected edge which connects country $x[i]$ and $y[i],ドル with time cost $c[i]$.
  • $arr$: an array with a length of $N$. $arr[i]$ represents the special ability of country $i$.
  • This procedure should return the minimum time to reach Cyberland from your country if you can reach Cyberland, and $-1$ if you cannot do so.
  • This procedure can be called more than once.

Assume that return value of contestant's is $ans_1,ドル and the return value of standard's is $ans_2,ドル your return value is considered correct if and only if $\frac{|ans_1 - ans_2|}{max{\{ans_2, 1\}}} \le 10^{-6}$.

Note: Since the procedure can be called more than once, contestants need to pay attention to the impact of the remaining data of the previous call on the current call.

입력

출력

제한

  • 2ドル ≤ N ≤ 10^5,ドル and $\sum{N} ≤ 10^5$.
  • 0ドル ≤ M ≤ \min{\{10^5, \frac{N(N-1)}{2}\}},ドル and $\sum{M} ≤ 10^5$.
  • 1ドル ≤ K ≤ 10^6$.
  • 1ドル ≤ H < N$.
  • 0ドル ≤ x[i], y[i] < N,ドル and $x[i] \ne y[i]$.
  • 1ドル ≤ c[i] ≤ 10^9$.
  • $arr[i] ∈ \{0, 1, 2\}$.
  • It is guaranteed that every pair of countries is connected by at most one road.

예제 1

Consider the following call:

solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1});

The only path to Cyberland is 0ドル → 2,ドル because you can not move to anywhere after reaching Cyberland. The calculation of passing time is shown as below.

country number passing time
0ドル$ 0ドル$
2ドル$ 0ドル + 4 → 4$ (sum) $→ 4$ (special ability)

Therefore, the procedure should return 4ドル$.

예제 2

Consider the following call:

solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1});

There are two paths from your country to Cyberland. They are: 0ドル → 1 → 3$ and 0ドル → 2 → 3$.

If your path is 0ドル → 1 → 3,ドル the calculation of passing time is shown as below.

country number passing time
0ドル$ 0ドル$
1ドル$ 0ドル + 5 → 5$ (sum) $→ 0$ (special ability)
3ドル$ 0ドル + 2 → 2$ (sum) $→ 2$ (special ability)

If your path is 0ドル → 2 → 3,ドル the calculation of passing time is shown as below.

country number passing time
0ドル$ 0ドル$
2ドル$ 0ドル + 4 → 4$ (sum) $→ 2$ (special ability)
3ドル$ 2ドル + 4 → 6$ (sum) $→ 6$ (special ability)

Therefore, the procedure should return 2ドル$.

서브태스크

번호배점제한
15

$N ≤ 3,ドル $K ≤ 30$.

28

$M = N - 1,ドル $K ≤ 30,ドル $arr[i] = 1,ドル you can travel from any countries to another via the $M$ edges.

313

$M = N - 1,ドル $K ≤ 30,ドル $arr[i] ∈ 0, 1,ドル you can travel from any countries to another via the $M$ edges.

419

$M = N - 1,ドル $K ≤ 30,ドル $x[i] = i,ドル $y[i] = i + 1$.

57

$K ≤ 30,ドル $arr[i] = 1$.

616

$K ≤ 30,ドル $arr[i] ∈ \{0, 1\}$.

729

$K ≤ 30$.

83

No additional constraints.

힌트

샘플 그레이더

The sample grader reads the input in the following format:

  • line 1ドル$: $T$

For each of the following $T$ test cases:

  • line 1ドル$: $N$ $M$ $K$
  • line 2ドル$: $H$
  • line 3ドル$: $arr[0]$ $arr[1]$ $arr[2]$ $\cdots$ $arr[N - 1]$
  • line 4ドル + i$ (0ドル ≤ i ≤ M - 1$): $x[i]$ $y[i]$ $z[i]$

The sample grader prints your answers in the following format:

For each test cases:

  • line 1ドル$: the return value of solve

출처

Olympiad > Asia-Pacific Informatics Olympiad > APIO 2023 A번

제출할 수 있는 언어

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

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

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

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