Strongly Connected Component

4

3 votes
Algorithms, Very-Easy
Problem

You are given a graph with N nodes and M directed edges. Find CD.

Where,

C Sum of number of nodes in all Strongly Connected Components with odd number of nodes.

D Sum of number of nodes in all Strongly Connected Components with even number of nodes.

Input:

First line contains 2 integers, N and M, denoting the number of nodes and the number of edges. Next M lines contain 2 integers A and B, meaning that there is a directed edge from A to B.

Output:

Output the number CD.

Constraints:

1N,M15

1A,BN

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

There are 2 strongly connected components, one has 1 node, and other has 4 nodes.

Therefore, C=1,D=4.

Editor Image

?