#P16007. [CCO 2016 Day 1] Field Trip

[CCO 2016 Day 1] Field Trip

题目描述

As a special treat for your kindergarten class, you're taking them on a field trip to a magical place of wonder.

Your class has NN students, numbered from 11 to NN for convenience. There are MM direct, two-way friendships that exist between the students. Each student is friends with at most two other students.

Aside from the MM direct friendships, students may also be acquainted with one another. Two students ii and jj are acquaintances if they're friends, or if there exists a third student kk who is an acquaintance of both students i and j. For example, if (1,2),(2,3),(3,4)(1, 2), (2, 3), (3, 4) and (4,5)(4, 5) are pairs of students with a direct friendship, then person 11 and person 55 are acquaintances.

You're getting ready to order buses for the trip, but there are two issues. Firstly, the transportation company insists that every bus you order must be filled exactly to its capacity of KK students. They won't allow you to order a bus if you intend to put fewer than KK students on it! Secondly, the students are picky about their travelling conditions. Each student ii will refuse to get on a bus unless both of the following conditions are met:

  1. All of the other students getting on that bus are acquaintances of student ii;
  2. All of student ii's acquaintances are getting on that bus.

Unfortunately, it looks like you might not be able to bring your whole class on this trip after all. However, you'll do whatever it takes to get as many students as possible on buses. As it turns out, "whatever it takes" may involve putting an end to a friendship or two, for the greater good. You may choose to sever 00 or more of the MM friendships amongst the students, which will of course also have an effect on which students are acquainted with one another.

Determine the maximum number of students which can be brought on the trip, such that they're loaded onto buses with exactly KK students each, and every student is satisfied with their bus allocation. Furthermore, since you're feeling generous, determine the minimum number of friendships which you can sever in order to be able to bring that many students along.

输入格式

The first line contains three space-separated integers N,MN, M and $K (1 \le N \le 10^6; 0 \le M \le 10^6; 1 \le K \le N)$.

The next MM lines contain information about the friendships. That is, each of these MM lines contain two space-separated integers AiA_i and Bi(1iM)B_i (1 \le i \le M) describing that students AiA_i and BiB_i are friends (1Ai,BiN,AiBi)(1 \le A_i, B_i \le N, A_i \neq B_i). Note that no friendship is specified twice (that is, no two unordered friendship pairs are equal to one another).

For 33 of the 2525 marks available, N1000N \le 1000.

输出格式

The output consists of two space-separated integers printed on one line. The first integer is the maximum number of students which can be brought on the trip. The second integer is the minimum number of friendships which must be severed in order to bring that many students.

8 5 2
1 4
8 2
4 5
6 2
3 5
6 2

提示

If the friendships between student pairs (8,2)(8,2) and (4,5)(4,5) are severed, then 33 buses can be filled as follows:

  • Bus 11: Students 11 and 44
  • Bus 22: Students 22 and 66
  • Bus 33: Students 33 and 55