#P17275. [eJOI 2026] Teamfulness
[eJOI 2026] Teamfulness
题目描述
While walking around Kaunas during EJOI, Anton discovered spots where participants hang out. The spots are numbered from to . Each spot is occupied by members of exactly one team, and teams are numbered from to . Members of the same team may occupy any number of spots, and some teams may occupy no spots.
The spots are connected by two-way roads such that there is exactly one simple path between any two spots; therefore, they form a tree. A simple path is a sequence of distinct spots in which every two consecutive spots are connected by a road. Its length is the number of roads it uses, one less than the number of spots it visits.
Anton wants to walk along a simple path and visit as many spots as possible. A simple path is interesting if its length is maximum among all simple paths in the tree. The teamfulness of a path is the number of distinct teams Anton encounters along it.
Find the sum of teamfulness over all different interesting paths. Two interesting paths are considered the same if and only if they visit exactly the same set of spots. In particular, traversing a path in the opposite direction does not create a different path.
Implementation details
Implement the following function:
long long teamfulness(int N, int K, std::vector<int> a,
std::vector<int> u, std::vector<int> v)
- : the number of spots;
- : the number of teams;
- : an array of integers, where is the team occupying spot ;
- : arrays of integers, where and are the spots connected by the -th road.
The function is called exactly once per test and must return the sum of teamfulness over all interesting paths.
输入格式
Input format:
- line : and ;
- line : integers ;
- line : two integers and , the endpoints of the -th road.
输出格式
Output format:
- line : the value returned by the function.
6 3
1 0 0 1 2 1
0 1
0 2
0 3
0 4
0 5
21
7 1
0 0 0 0 0 0 0
0 1
0 2
1 3
1 4
2 5
2 6
4
6 3
0 1 2 0 1 2
0 1
1 2
2 3
1 4
2 5
11
提示
Explanation of example 1
The maximum length of a simple path is , so interesting paths have roads and spots. There are two interesting paths with teamfulness , seven with teamfulness , and one with teamfulness , giving a total of .
Explanation of example 2
Team is shown in yellow:
:::align{center}
:::
Every path has teamfulness because there is only one team. There are four interesting paths of length , so the sum is .
Explanation of example 3
Team is yellow, team is green, and team is red:
:::align{center}
:::
Interesting paths have length . There are four interesting paths: three have teamfulness , and one has teamfulness . Their total teamfulness is .
Constraints
- for every
- for every
Subtasks
| Subtask | Points | Additional constraints | ||
|---|---|---|---|---|
| 0 | - | The examples. | ||
| 1 | 4 | Every spot is directly connected to at most two other spots. | ||
| 2 | 7 | Some spot is directly connected to every other spot. | ||
| 3 | 9 | - | ||
| 4 | 10 | |||
| 5 | ||||
| 6 | 9 | |||
| 7 | 11 | |||
| 8 | 12 | |||
| 9 | 13 | The length of an interesting path is odd. | ||
| 10 | 15 | - | ||