P20943 [GeeksforGeeks] Message spreading4258
普及-
题目描述

There are N students in a class, each in possession of a different funny story.
They want to share funny stories with each other by sending electronic messages. Assume that a sender includes all the funny stories he or she knows at the time the message is sent and that a message may only have one addressee. What is the minimum number of messages they need to send to guarantee that every one of them gets all the funny stories?

Example 1:
Input:
2
Output:
2
Explanation:
Person 1 sends a message to
Person 2, Person 2 sends
message to Person 1.
A total of 2 messages are sent.

Example 2:
Input:
1
Output:
0
Explanation:
No messages are sent.

Your Task:
You don't need to read input or print anything. Your task is to complete the function minimumMessages() which takes an integer N and returns the minimum number of messages they need to send to guarantee that every one of them gets all the funny stories.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1<=N<=10^{5}

输入格式

见题面

输出格式

见题面

样例输入
2
样例输出
2