Jamie and Interesting Graph

CodeForces - 916C