Editorial for COCI '22 Contest 2 #5 Kruhologija
Submitting an official solution before solving the problem yourself is a bannable offence.
We can use the Euler characteristic of the surface, mainly where is the number of holes. Now we have to count , , and . To count , we can simply do a DFS on the faces, marking each face we visit. The number of visited nodes is exactly . Because each face has degree exactly , by the handshaking lemma .
The trickiest part is counting the vertices. For each face, you can calculate the degrees of the four vertices forming the side. Let's say you are trying to calculate the degree of the left vertex of the edge you are pointing at. You can mark the current face and start a "left cycle" until you return to the marked face. The number of faces you visit is exactly the degree of the vertex, you can easily see this by "flattening" out the part around that vertex, it essentially looks like a flower with either , , or petals. Now you can easily infer the total number of vertices and then the total number of holes!
Comments