GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Monday 2 May 2022

Remove Directed Edges Codeforces Solution | Codeforces Problem Solution 2022

G. Remove Directed Edges
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a directed acyclic graph, consisting of n vertices and m edges. The vertices are numbered from 1 to n. There are no multiple edges and self-loops.

Let inv be the number of incoming edges (indegree) and outv be the number of outgoing edges (outdegree) of vertex v.

You are asked to remove some edges from the graph. Let the new degrees be inv and outv.

Solution Click Below:-  CLICK HERE

You are only allowed to remove the edges if the following conditions hold for every vertex v:

  • inv<inv or inv=inv=0;
  • outv<outv or outv=outv=0.

Let's call a set of vertices S cute if for each pair of vertices v and u (vu) such that vS and uS, there exists a path either from v to u or from u to v over the non-removed edges.

What is the maximum possible size of a cute set S after you remove some edges from the graph and both indegrees and outdegrees of all vertices either decrease or remain equal to 0?

Input

The first line contains two integers n and m (1n21050m2105) — the number of vertices and the number of edges of the graph.

Each of the next m lines contains two integers v and u (1v,unvu) — the description of an edge.

The given edges form a valid directed acyclic graph. There are no multiple edges.

Output

Print a single integer — the maximum possible size of a cute set S after you remove some edges from the graph and both indegrees and outdegrees of all vertices either decrease or remain equal to 0.

Join Now for Solution:- 

                                                                        

No comments:

Post a Comment