Maximum size of a set
Practice
2.2 (12 votes)
Algorithms
C++
Graphs
Sorting
Problem
64% Success 1923 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a DAG with N nodes and M edges. You are building a graph G^. G^ contains the same vertex set as G and all edges are available in G. Moreover,

  1. If there exists an edge between vertex u and v in G, then there does not exist an edge between vertex v and u in G^.
  2. If there exists an edge between vertex u and v in G and also between v and w in G, then there exists an edge between vertex u and w in G^.

For G^, find the maximum possible size of where S is a set of vertices in G^ such that there exists an edge between every unordered pair of vertex present in S.

The meaning of unordered is that there must exist an edge between every pair of vertex (u,v), that is, either u - > v or v - > u must be in an edge set.

Input format

  • The first line contain two integer N and M describing nodes and edges in graph G.
  • Next M lines contain two integers u and v representing an edge from u to v.

Output format
Print the maximum possible size of set S.

Constraints
\(1 \le N \le 200000\\ 1 \le M \le 1000000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
GraphTreeAlgorithmsGraphsTopological Sort
Points:30
65 votes
Tags:
AlgorithmsApprovedData StructuresDepth First SearchGraphsMediumOpenSorting
Points:30
2 votes
Tags:
Topological SortAlgorithmsGraphs