Editorial for JOI '22 Open P3 - School Road
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors: ,
Review:
Proof:
In this task, given an undirected weighted graph with  vertices and 
 edges, we need to determine whether
there exist more than one values of the lengths of simple paths (paths without visiting the same vertex more
than once) from 
 to 
.
Subtask 1 (
)
We first consider a solution to search all the possibilities.
Let us calculate all the simple paths starting from  by DFS. What is the time complexity?
Let  be the maximum of "the number of simple paths starting from 
" for an undirected graph with 
edges. By a case-by-case analysis according to the degree of the vertex 
, we see that
holds. We estimate the upper bound using this recurrence formula. Then we have . Therefore,
this subtask can be solved by DFS whose time complexity is 
.
Subtask 2 (
)
If there exist multiple edges, we can use only one of them to make a simple path. We shall replace multiple edges by an edge.
Since we are finding paths with different lengths, we do not need several edges of the same length. We only
need two edges of different lengths. Therefore, for each pair of vertices, we only need an edge of minimum
length and an edge of maximum length. Then, the total number of edges becomes .
After that, it is enough to calculate a shortest simple path and a longest simple path. We can calculate a
shortest simple path by Dijkstra's algorithm whose time complexity is . But we cannot calculate a longest
simple path by the same method. Since 
, we can calculate it by bitDP. We put
We can solve this subtask in  time.
Subtask 3 (
)
In this subtask,  is close to 
. This means the average degree of the vertices is close to 
, and more than
half of the vertices have degree 
.
Except for  and 
, we will never use a vertex of degree 
. Thus, we can delete it and the edge connecting
with it. Repeating this, we may assume that almost all vertices have degree 
.
Except for  and 
, if one visits a vertex of degree 
 by passing through an edge, one will leave it by passing
through the other edge. Thus, we can regard a vertex of degree 
 together with the two edges as an edge. We
replace a vertex of degree 
 together with the two edges by an edge. Repeating this, we may assume that all the
vertices other than 
 have degree 
.
By the above processes, the graph becomes a graph satisfying , 
, 
. Since 
is close to the constraints of Subtask 1, we can solve it using the solution of Subtask 1.
When , one may wonder if "the number of simple paths (of length 
) starting from 
" becomes
larger than Subtask 1. However, due to the constraints 
, this value actually cannot be larger than
Subtask 1.
Subtask 4 (if 
, then there exists an 
 path without passing through the vertex 
)
What is the meaning of this constraint?
If there exists a triple  such that every 
 path passes through the vertex 
, then 
 becomes
disconnected if we delete the vertex 
. In other words, the vertex 
 is an articulation point. Conversely, if there
exists an articulation point, there exists a triple 
 such that every 
 path passes through the vertex 
.
Therefore, the condition that such a triple does not exist means every vertex is not an articulation point. Hence
the graph is 
-vertex-connected.
Assume that the graph is -vertex-connected. Then for every edge 
, there exists a simple 
 path
containing the edge 
.
Proof We add the vertices
and the edges
,
,
,
. After that, the graph is still
-vertex-connected. There exist two simple paths from
to
which do not share a common vertex except for the end points (Menger's theorem). We delete the vertices
from the two simple paths and add the edge
to connect them. Then we obtain a desired simple path.
Therefore, if there exist multiple edges with different lengths, the answer is . If there exist multiple edges
with the same length, we may replace them by an edge. We may assume that the graph is simple.
By the same way as in Subtask 3, we compress the vertices of degree . We may assume that all the vertices
other than 
 have degree 
.
After that, if only the edge  remains, the answer is obviously 
. Otherwise, one may wonder if the
answer is always 
. We shall prove it.
Prerequisite conditions
- The graph is simple and 
-vertex-connected.
 - All the vertices other than 
have degree
.
 - There exist at least 
vertices. (The above condition cannot be satisfied if there exist less than
vertices.)
 
Let  be the minimum distance between 
 and 
. We may assume that every edge 
 satisfies
or
Otherwise, there exists an edge which does not satisfy this condition. Then, there exists a simple  path
containing it, and the answer is 
.
We give orientations to the edges so that every edge moves farther from the vertex  (i.e., every edge gets
close to the vertex 
). If the indegree of a vertex is larger than the outdegree, we mark it as red. Other vertices
are colored blue.
Let  be a path from 
 to 
 passing through the maximum number of edges. Since 
 contains at least 
vertices and it passes through the maximum number of edges, the vertex on the path 
 next to 
 is blue and the
vertex just before 
 is red. There exists an edge on the path 
 which changes the color from blue to red. Let
 be such an edge.
Here the vertex  is blue, and the vertex 
 is red. There exist edges 
, 
 other than the edge 
.
We take shortest paths 
 and 
. We consider the path 
. The path 
is simple (if it is not simple, then there exists a path whose number of edges is larger than 
), and its length is
larger than 
.
Therefore, the answer is .
In summary, after replacing multiple edges by an edge and contracting vertices of degree , if only the edge
 remains, the answer is 
. If there exist multiple edges with different lengths or an edge other than 
remains, the answer is 
. The time complexity is 
.
Subtask 5
In this subtask, the difference from Subtask 4 is that there may exist articulation points. Also, there may exist
a vertex such that if one visits it from , then one cannot visit 
 afterward. We need to delete unnecessary parts
from the graph.
We decompose the graph into -vertex-connected components. We only need 
-vertex-connected components
between 
 and 
 because if one tries to pass through an edge outside such components, one has to pass through
an articulation point more than once.
We add an edge of length  between 
 and 
. Then, we only need the 
-vertex-connected component
containing the 
 edge.
After deleting unnecessary parts from the graph, we can solve this subtask by the same way as Subtask 4.
The time complexity is .
Comments