Enemy Division
Time limit1sMemory limit128 MB
Divide soldiers into the fewest groups so that each soldier shares a group with at most one enemy, where every soldier has at most 3 enemies.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
It is the year 2147 and a great war rages across the world. Captain Keram's soldiers have fought side by side since the war began two years ago, and along the way some of them have become enemies of one another. Fortunately, each soldier has at most 3 enemies.
They must soon attack another country, and Keram worries that soldiers who are enemies might not cooperate during battle. He has therefore decided to split the soldiers into groups so that every soldier has at most one of his enemies in his own group. He also wants to keep things simple, so he wants to use as few groups as possible. Help Captain Keram by finding the minimum number of groups he needs.
Input
The first line contains two integers and (, ), where is the number of soldiers and is the number of enemy pairs.
Each of the next lines contains two space-separated integers and (), meaning that soldiers and are enemies. You may assume that every soldier has at most 3 enemies.
Output
Output a single integer: the minimum number of groups such that the soldiers can be split into groups with every soldier sharing his group with at most one of his enemies.