#P14997. [Nordic OI 2020] Christmas Gifts

[Nordic OI 2020] Christmas Gifts

题目描述

At the Nordic Olympic Institute (NOI) the SS students have a tradition of exchanging gifts with their friends at christmas. More precisely, if AA and BB are friends either AA gives BB a gift or BB gives AA 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 AA and BB, you have to decide if AA should give a gift to BB or BB should give a gift to AA.

Let gig_i be the number of gifts student ii gives, and rir_i the number of gifts student ii receives. The NOI administration has decided a fair gift exchange is one that minimizes the unfairness score i=1Sgiri\sum_{i=1}^{S} |g_i - r_i|.

Given the list of FF 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 1,,S1, \ldots, S instead of using their names.

输入格式

  • Line 1: The integers SS and FF separated by space (2S1000002 \leq S \leq 100000 and 1F2000001 \leq F \leq 200000).
  • Next FF lines: The integers AA and BB separated by space, meaning AA and BB are friends (1A<BS1 \leq A < B \leq S).

(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 FF lines: The integers AA and BB meaning AA should give a gift to BB (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 S10S \leq 10 and F20F \leq 20
2 S500S \leq 500 and F10000F \leq 10000
3 50 No extra constraints.
4 20 All students have an even number of friends.