Bosses

Time limit1sMemory limit1024 MB

Summary
Given a graph of projects where the lower-numbered endpoint is the boss, find the max number of edges so every vertex has at most one boss, minimizing cancellations.
Level

Medium4 of 10

Topics
Graph, Greedy, Implementation, Sorting
Solved
No attempts yet

Problem

Company “Ūbr” employs NN programmers. Each is assigned a code — an integer from 11 to NN. All employees' codes are distinct.

The company runs MM projects. Each project is the joint responsibility of two programmers, and the one with the smaller code is the other's boss. It is guaranteed that no pair of employees works together on more than one project.

Figure 1. In this example N=6N = 6 and five projects are running. The second, third, and sixth programmers each have one boss, while the fourth programmer has two bosses.

“Ūbr” has found that programmers with more than one boss enjoy their work less. The company wants to reorganize so that every employee has at most one boss. It will do this by terminating some existing projects and starting new ones. In the example above, one valid reorganization is to cancel project 3–4 and create the new project 3–5, but that is not the only option.

Find a way for “Ūbr” to reorganize so that no programmer has two or more bosses. Among all such reorganizations, the company wants to run as many projects as possible after the change; and among those, it wants to cancel as few of the original projects as possible.

Input

The first line contains two integers — the number of programmers NN and the number of projects MM run before the reorganization. Each of the next MM lines describes one project with two distinct integers between 11 and NN: the codes of the two programmers responsible for that project.

Output

Output three integers KK, PP, SS on a single line, separated by spaces:

  • KK — the number of projects the company will run after the reorganization
  • PP — the number of projects that will be terminated
  • SS — the number of new projects that will be started

They must satisfy K=M−P+SK = M - P + S. Choose the reorganization that first maximizes KK, and then, among those, minimizes PP. Under these two conditions the values KK, PP, and SS are uniquely determined, so output exactly those three numbers.

Constraints

  • 1≤N≤1061 \le N \le 10^6
  • 0≤M≤1060 \le M \le 10^6

Examples2

  1. Example 1

    Input
    6 5
    1 2
    1 3
    4 2
    4 3
    5 6
    
    Expected output
    5 1 1
    
  2. Example 2

    Input
    3 0
    
    Expected output
    2 0 2