Editorial for IOI '12 P2 - Parachute Rings
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
A suboptimal solution covering all but the last subtask considers the following conditions:
- if there is a vertex of degree , no other vertex can be critical (because removing still leaves one or more vertices of degree ); so if there is more than one vertex of degree , there are no critical vertices;
- if there is a vertex of degree , each critical vertex is either or one of its neighbors;
- if there is a cycle, all critical vertices lie on the cycle;
- if the graph is linear (a set of disjoint paths), all of its vertices are critical.
These checks can be easily extended to the dynamic case of the last subtask: the only nontrivial check is keeping track of cycle formation, which can be dealt with using suitable data structures (union-find d.s., etc.).
Comments