First of all you have given a graph with undirected edges.You have to give a direction to each edge such that indegree of all vertices to be even? Question Link My ApproachInitially i have given all the edges same direction as i am taking input.
First of all if number of edges are odd so no possible direction of all edges can make it a graph with even indegree. so if m is odd ans will be 1. while taking input i have made the graph. Then using BFS i have converted into a tree. Any possible tree can be made consisting of all vertices (n) ans n1 edges. After that i used a set to insert all the nodes having odd indegree. Euler tour is used to convert a tree into a 1D array. This is used to make indegree even. bool flag = false;
Now reversing all the edges direction in between two nodes with odd indegree will make indegree of all inbetween nodes even as by doing so, indegree of inbetween nodes will remain same of increased by 2 or decreased by 2. HOW???? Just try to make some cases using pen and paper. And indegree of both nodes with odd indegree will become even. asked 18 Dec '18, 17:58
