#P2962. [USACO09NOV] Lights G

    ID: 2003 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索2009USACOO2优化深度优先搜索,DFS高斯消元

[USACO09NOV] Lights G

Description

Bessie and the cows were playing games in the barn, but the power was reset and the lights were all turned off. Help the cows get all the lights back on so they can resume their games.

The N(1N35)N(1 \le N \le 35) lights conveniently numbered 1N1 \cdots N and their switches are arranged in a complex network with M(1M595)M(1 \le M \le 595) clever connection between pairs of lights (see below).

Each light has a switch that, when toggled, causes that light -- and all of the lights that are connected to it -- to change their states (from on to off, or off to on).

Find the minimum number of switches that need to be toggled in order to turn all the lights back on.

It's guaranteed that there is at least one way to toggle the switches so all lights are back on.

Input Format

  • Line 11: Two space-separated integers: NN and MM.
  • Lines 2M+12 \cdots M+1: Each line contains two space-separated integers representing two lights that are connected. No pair will be repeated.

Output Format

  • Line 11: A single integer representing the minimum number of switches that need to be flipped in order to turn on all the lights.
5 6 
1 2 
1 3 
4 2 
3 4 
2 5 
5 3 

3 

Hint

Explanation

There are 55 lights. Lights 1,41,4 and 55 are each connected to both lights 22 and 33.

Toggle the switches on lights 1,41, 4 and 55.