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

Janjetina

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

의견: 0

설명

After restaurants all over Croatia closed because of the lockdown, Mr. Malnar was first
overwhelmed with sadness. But he soon realized that there was no point in being sad,
and he decided that as soon as the restaurants reopen, he will travel around Croatia and
treat himself with the best lamb Croatian restaurants can offer.
Mr. Malnar knows about \(n\) cities he could visit, that he labeled with integers from 1
through \(n\). Also, he knows about \(n - 1\) t\(wo-wa\)y roads that connect those cities, in such a way that it is
possible to travel between any two cities.
On every road there is a restaurant that serves lamb, and Mr. Malnar knows how many kilograms of
lamb he can order in each one.
He will choose two different cities \(x\) and \(y\), and travel from \(x\) to \(y\) via the shortest path, i.e. the path
that uses the minimal number of roads. He will stop at exactly one restaurant, the one where he can
order the maximum amount of lamb (if there are multiple such restaurants, he will choose any of them),
and he will of course eat all the lamb he orders.
Mr. Malnar considers a path of length \(l\) on which he eats \(w\) kilograms of lamb to be satisfactory if
\(w - l \ge k\). The length of a path is equal to the number of roads that it goes through.
He wonders how many ordered pairs of distinct cities (x, y) there are, such that the shortest path from \(x\)
to \(y\) is satisfactory. He is very busy, so he asks you to calculate the answer for him.

제약

Subtask 1 (15 points): \(1 \le n \le 1000\)

Subtask 2 (35 points): Cities \(i\) and \(i + 1\) (\(1 \le i \le n - 1\)) are directly connected.

Subtask 3 (60 points): No additional constraints.

입력 형식

The first line contains integers \(n\) and \(k\) (\(1 \le n\), \(k \le 100\,000\)), the number of cities, and the satisfaction
threshold.
Each of the following \(n - 1\) lines contains three integers \(x\), \(y\) and \(w\) (\(1 \le x\), \(y \le n\), \(x\)̸ = y, \(1 \le w \le 100\,000\)),
which means that there is a road that connects \(x\) and \(y\), and there is a restaurant on that road where Mr.
Malnar can order \(w\) kilograms of lamb.

출력 형식

Output the number of ordered pairs of distinct cities (x, y), such that the shortest path from \(x\) to \(y\) is
satisfactory.

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

1

15점

\(1 \le n \le 1000\)

2

35점

Cities \(i\) and \(i + 1\) (\(1 \le i \le n - 1\)) are directly connected.

3

60점

No additional constraints.

예제 1
입력
3 1
1 2 3
1 3 2
출력
6
예제 2
입력
4 1
1 2 1
2 3 2
3 4 3
출력
6
예제 3
입력
5 2
1 2 2
1 3 3
3 4 2
3 5 4
출력
8
문제 정보

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

출처 COCI 2020/2021 Contest 4

평가 및 의견

Janjetina

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

Log in to rate problems.

개별 의견

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

풀이 제출

Janjetina

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