#P14997. [Nordic OI 2020] Christmas Gifts
[Nordic OI 2020] Christmas Gifts
题目描述
At the Nordic Olympic Institute (NOI) the students have a tradition of exchanging gifts with their friends at christmas. More precisely, if and are friends either gives a gift or gives a gift.
Last christmas there was a big scandal at NOI because some of the students received a lot of gifts without giving any and some students gave a lot of gifts without receiving any. NOI needs your help to make this christmas gift exchange more fair. You need to decide who should give gifts to whom, ie. for each friendship between and , you have to decide if should give a gift to or should give a gift to .
Let be the number of gifts student gives, and the number of gifts student receives. The NOI administration has decided a fair gift exchange is one that minimizes the unfairness score .
Given the list of friendships, compute the minimum possible unfairness score and for each friendship write out who should give a gift to whom. Due to GDPR concerns, all students have been numbered from instead of using their names.
输入格式
- Line 1: The integers and separated by space ( and ).
- Next lines: The integers and separated by space, meaning and are friends ().
(All friendships in the input are mutual and a friendship will only appear once in the input)
输出格式
- Line 1: The minimum possible unfairness score.
- Next lines: The integers and meaning should give a gift to (you can output these lines in any order, but each friendship must be in the output exactly once).
4 5
1 2
2 3
2 4
1 3
3 4
2
2 4
4 3
1 3
3 2
2 1
提示
In this example we have 4 students and 5 friendships. The shown solution is not unique - any correct solution will be accepted.
Scoring
Your solution will be tested on a set of test case groups. To get the points for a group, you need to pass all the test cases in the group.
| # | Points | Constraints |
|---|---|---|
| 1 | 15 | and |
| 2 | and | |
| 3 | 50 | No extra constraints. |
| 4 | 20 | All students have an even number of friends. |