RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00611

Autobus

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

In a country there are \(n\) cities. The cities are connected by \(m\) bus routes, where
the \(i-th\) route starts in city \(a_{i}\), ends in city \(b_{i}\) and takes \(t_{i}\) minutes.
Ema loves to travel, but doesn’t like transferring between buses. On her trip
she wants to use at most \(k\) different bus routes.
Help her answer \(q\) questions of the form ‘What is the shortest travel time to
get from city \(c_{j}\) to city \(d_{j}\) (using at most \(k\) different bus routes)?’.

제약

Subtask 1 (15 points): \(k \le n \le 7\)

Subtask 2 (15 points): \(k \le 3\)

Subtask 3 (25 points): \(k \le n\)

Subtask 4 (15 points): No additional constraints.

입력 형식

The first line contains two positive integers \(n\) and \(m\) (\(2 \le n \le 70\), \(1 \le m \le 10^{6}\)), the number of cities and
the number of bus routes.
The \(i-th\) of the next \(m\) lines contains positive integers \(a@@RISE_MATH_BLOCK_0@@i\) and \(t@@RISE_MATH_BLOCK_1@@i\), b\(i \le n\), \(1 \le t\)\(i \le 10^{6}\)), the
terminal cities and the travel time of the \(i-th\) bus route.
The next line contains two positive integers \(k\) and \(q\) (\(1 \le k \le 10^{9}\), \(1 \le q \le n\)^{2}), the maximum number of
used routes and the number of queries.
The \(j-th\) of the next \(q\) lines contains positive integers \(c_{j}\) and \(d_{j}\) (\(1 \le c_{j}\), \(d_{j} \le n\)), the cities from the \(j-th\)
query.

출력 형식

Print \(q\) lines. In the \(j-th\) line print the shortest travel time from the \(j-th\) query, \(or -1\) if there is no trip
that satisfies the requirements.

서브태스크
서브태스크점수설명

1

15점

\(k \le n \le 7\)

2

15점

\(k \le 3\)

3

25점

\(k \le n\)

4

15점

No additional constraints.

예제 1
입력
4 7
1 2 1
1 4 10
2 3 1
2 4 5
3 2 2
3 4 1
4 3 2
1 3
1 4
4 2
3 3
출력
10
-1
0
예제 2
입력
4 7
1 2 1
1 4 10
2 3 1
2 4 5
3 2 2
3 4 1
4 3 2
2 3
1 4
4 2
3 3
출력
6
4
0
예제 3
입력
4 7
1 2 1
1 4 10
2 3 1
2 4 5
3 2 2
3 4 1
4 3 2
3 3
1 4
4 2
3 3
출력
3
4
0
설명

Clarification of the examples:
The answer to the first query from each example is marked on the graph.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2021/2022 Contest 4

평가 및 의견

Autobus

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Autobus

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8