Remove Directed Edges Codeforces Solution | Codeforces Problem Solution 2022
You are given a directed acyclic graph, consisting of vertices and edges. The vertices are numbered from to . There are no multiple edges and self-loops.
Let be the number of incoming edges (indegree) and be the number of outgoing edges (outdegree) of vertex .
You are asked to remove some edges from the graph. Let the new degrees be and .
You are only allowed to remove the edges if the following conditions hold for every vertex :
- or ;
- or .
Let's call a set of vertices cute if for each pair of vertices and () such that and , there exists a path either from to or from to over the non-removed edges.
What is the maximum possible size of a cute set after you remove some edges from the graph and both indegrees and outdegrees of all vertices either decrease or remain equal to ?
The first line contains two integers and (; ) — the number of vertices and the number of edges of the graph.
Each of the next lines contains two integers and (; ) — the description of an edge.
The given edges form a valid directed acyclic graph. There are no multiple edges.
No comments:
Post a Comment