F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Necklace

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 4424    Accepted Submission(s): 1316


Problem Description
SJX has 2*N magic gems. $N$ of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid making the necklace too Yin or too Yang, he must place these magic gems Yin after Yang and Yang after Yin, which means two adjacent gems must have different kind of energy. But he finds that some gems with Yang energy will become somber adjacent with some of the Yin gems and impact the value of the neckless. After trying multiple times, he finds out M rules of the gems. He wants to have a most valuable neckless which means the somber gems must be as less as possible. So he wonders how many gems with Yang energy will become somber if he make the necklace in the best way.
 

Input
  Multiple test cases.

  For each test case, the first line contains two integers $N (0 \leq N \leq 9), M (0 \leq M \leq N * N)$, descripted as above.

  Then $M$ lines followed, every line contains two integers $X,Y$, indicates that magic gem $X$ with Yang energy will become somber adjacent with the magic gem $Y$ with Yin energy.
 

Output
One line per case, an integer indicates that how many gem will become somber at least.
 

Sample Input
2 1 1 1 3 4 1 1 1 2 1 3 2 1
 

Sample Output
1 1
 

Author
HIT
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-24 13:31:06, Gzip enabled