We will hold AtCoder Beginner Contest 482.
- Contest URL: https://atcoder.jp/contests/abc482
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20261031T2100&p1=248
- Duration: 100 minutes
- Writer: Nyaan, KumaTachiRen, milkcoffeen
- Tester: kyopro_friends, vwxyz0
- Rated range: ~ 1999
- The point values: 100-200-300-400-475-525-650
We are looking forward to your participation!








Hope that I can solve problem E.
不是啊,C题咋做?
Sorting + Binary Search
We only need to count how many pieces have a row or column coordinate inside a given interval.
Store all row coordinates in one array and all column coordinates in another, then sort both arrays.
For each query:
Using binary search, the answer is:
sorry, but why are you giving away the solution during the contest?
But Wht?!
USE ENGLISH Please
(I am from China)Why?
Because of the community rule. You didn't even read the community rule before posting your comment?
How to solve $$$E$$$ :(
I used dsu on tree.
where to see contest probs
This is how I did it:
The problem asks us to count pairs of vertices $$$(u,v)$$$ satisfying:
The diameter is the maximum distance between any two vertices in a tree. We can calculate it using two BFS traversals and reconstruct the diameter path using parent pointers.
First, we perform BFS from an arbitrary vertex (vertex $$$1$$$) to find a farthest vertex $$$A$$$. Then, we perform another BFS starting from $$$A$$$ to find a farthest vertex $$$B$$$.
The distance between $$$A$$$ and $$$B$$$ gives the diameter:
We also store the parent array during the second BFS to reconstruct the diameter path.
The center of a tree is the middle of its diameter. Depending on whether the diameter is even or odd, there are two possibilities.
Case 1: Diameter is even
Let the diameter be $$$D=2k$$$. Since the diameter is even, the tree has a unique center vertex $$$c$$$.
We can obtain this center from the reconstructed diameter path:
Consider two vertices $$$u$$$ and $$$v$$$ whose distance equals the diameter. Since their path is a diameter path, it must pass through the center $$$c$$$. Therefore,
Since $$$c$$$ is the center, the maximum distance of any vertex from $$$c$$$ is $$$k$$$. Hence,
For their sum to equal $$$2k$$$, both distances must be exactly $$$k$$$.
Additionally, the two vertices must belong to different connected components after removing $$$c$$$, since their path must pass through the center.
Thus, the problem reduces to counting pairs of vertices that:
We first perform BFS from the center to calculate the distance of every vertex from it.
Next, we process each subtree adjacent to the center independently. We collect all vertices at distance exactly $$$k$$$ from the center in the current subtree.
We maintain a frequency map
mp, where:For every collected vertex $$$u$$$, we query:
After processing all queries for the current subtree, we insert its vertices into the map by incrementing their corresponding color frequencies.
Processing queries before insertions ensures that we only count pairs belonging to different subtrees.
Case 2: Diameter is odd
Let the diameter be $$$D=2k+1$$$. Since the diameter is odd, the tree has two centers, say $$$c_1$$$ and $$$c_2$$$, connected by an edge.
We can obtain these centers from the reconstructed diameter path:
Consider two vertices $$$u$$$ and $$$v$$$ whose distance equals the diameter. Their path must pass through the central edge $$$(c_1,c_2)$$$.
Without loss of generality, let $$$u$$$ belong to the component containing $$$c_1$$$, and $$$v$$$ belong to the component containing $$$c_2$$$, after removing the central edge.
We have:
Since the diameter is $$$2k+1$$$,
The maximum distance of any vertex from either center, within its respective component, is $$$k$$$. Therefore,
Thus, the problem reduces to counting pairs of vertices having the same color, where one vertex is at distance $$$k$$$ from $$$c_1$$$ on its side and the other is at distance $$$k$$$ from $$$c_2$$$ on its side.
We solve this using a frequency map.
Step 1: Process the first component.
We perform BFS starting from $$$c_1$$$, keeping track of the current vertex, its parent, and its distance from $$$c_1$$$.
We explicitly avoid traversing the central edge $$$(c_1,c_2)$$$ so that we remain within the component containing $$$c_1$$$.
Whenever we reach a vertex at distance exactly $$$k$$$, we increment its color frequency in the map:
Step 2: Process the second component.
Similarly, we perform BFS starting from $$$c_2$$$, avoiding the central edge $$$(c_2,c_1)$$$.
Whenever we reach a vertex $$$v$$$ at distance exactly $$$k$$$, we add its corresponding color frequency to the answer:
Since the two components are disjoint, every counted pair automatically has distance exactly $$$2k+1$$$, and every valid pair is counted exactly once.
Could someone explain their solution for F ?
Update: The japanese tutorial is already out so if anybody is also curious about the solution they can translate that using some LLM.
please translate editorial in english
About problem G:
I've seen there is an unofficial editorial that talks about a solution using Edmonds' Blossom algorithm. I don't understand how the author managed to make it run in 96ms, because I did exactly that on contest but my solution TLE-ed on 2 test cases. chuanyu.fan would you mind sharing your code or explaining any kind of pruning you did to make it run that fast? Thanks.
Is AtCoder necessary while practicing CF daily?? Please help, I am a beginner:)