HDU 3498 (repeated DLX overwrite)

Source: Internet
Author: User

Simply repeat the questions...

 

Whosyourdaddy

time limit: 20000/10000 MS (Java/others) memory limit: 65536/65536 K (Java/others) total submission (s): 1022 accepted submission (s ): 502

Problem descriptionsevenzero liked Warcraft very much, but he haven'tpracticed it for several years after being addicted to algorithms. now, though he is playing with computer, he nearly losed and only his hero pit lord left. sevenzero is angry, he decided to cheat to turn defeat into victory. so he entered "whosyourdaddy", that let Pit Lord kill any hostile unit he damages immediately. as all warcrafters know, pit lord masters a skill called cleaving attack and he can damage neighbor units of the unit he attacks. pit Lord can choice a position to attack to avoid killing partial neighbor units sevenzero don't want to kill. because sevenzero wants to win as soon as possible, he needs to know the minimum attack times to eliminate all the enemys.

 

Inputthere are several cases. for each case, first line contains two integer N (2 ≤ n ≤ 55) and M (0 ≤ m ≤ n * n), and N is the number of hostile units. hostile units are numbered from 1 to n. for the subsequent M lines, each line contains two integers A and B, that means a and B are neighbor. each unit has no more than 4 neighbor units. the input is terminated by EOF.

 

Outputone line shows the minimum attack times for each case.

 

Sample input5 4
1 2
1 3
2 4
4 5
6 4
1 2
1 3
1 4
4 5

 

Sample output2
3

 

Authorsevenzero

 

Source2010 ACM-ICPC multi-university training Contest (7) -- host by hit

 

Recommendzhouzeyong
# Include <stdio. h> # Include < String . H> # Include <Iostream> Using   Namespace  STD;  # Define N 5000 # Define INF 0x3ffffff Struct  Node { Int  To, next;} edge [N];  Int  R [N], L [N], U [N], d [N], num [N], Col [N], line [N], H [N];  Int  Head;  Int  N, m;  Int G [ 60 ] [ 60  ];  Int  Nn, mm;  Int CNT, pre [ 60 ];  Int  ID;  Int  Mi;  Void Add_edge ( Int X, Int  Y) {edge [CNT]. = Y; edge [CNT]. Next = Pre [X]; Pre [x] = CNT ++ ;}  Void  Prepare (){  For (Int I = 0 ; I <= mm; I ++ ) {Num [I] = 0  ; U [I] = I; d [I] = I; R [I] = I + 1  ; L [I + 1 ] = I;} R [mm] = 0  ; L [  0 ] =Mm; memset (H, - 1 , Sizeof  (H ));}  Void Link ( Int TN, Int  TM) {ID ++ ; Num [line [ID] = Tm] ++ ; Col [ID] = TN; U [d [Tm] = ID; d [ID] = D [Tm]; U [ID] =TM; d [Tm] = ID;  If (H [tn] < 0 ) H [tn] = R [ID] = L [ID] = ID;  Else  {L [R [H [tn] = ID; R [ID] = R [H [tn]; L [ID] = H [tn]; R [H [tn] = ID ;}}  Void  Build () {ID =Mm; prepare ();  For ( Int I = 1 ; I <= N; I ++ ) {Link (I, I );  For ( Int P = pre [I]; P! =- 1 ; P = Edge [p]. Next ){  Int V = Edge [p]. To; Link (I, V );}}}  Int  H (){ Int Mark [ 60  ]; Memset (mark,  0 , Sizeof  (Mark ));  Int Sum = 0  ;  For ( Int I = R [head]; I! = Head; I = R [I]) {  If (MARK [I] = 0 ) {Sum ++ ;  For ( Int J = d [I]; J! = I; j = D [J])  For ( Int K = R [J]; k! = J; k = R [k]) MARK [line [k] = 1  ;}}  Return  SUM ;}  Void Remove (Int  S ){  For ( Int I = d [s]; I! = S; I = D [I]) {L [R [I] = L [I]; R [L [I] = R [I] ;}}  Void Resume ( Int  S ){  For ( Int I = d [s]; I! = S; I = D [I]) L [R [I] = R [L [I] =I ;}  Void DFS ( Int  S ){  If (S + H ()> = mi) Return  ;  If (R [head] = Head) {mi = S;  Return  ;}  Int TMI = INF, Tu;  For (Int I = R [head]; I! = Head; I = R [I])  If (Num [I] < TMI) {TMI = Num [I]; TU = I ;}  For ( Int I = d [Tu]; I! = Tu; I = D [I]) {remove (I );  For ( Int J = R [I]; J! = I; j = R [J]) Remove (j); DFS (S +1  );  For ( Int J = L [I]; J! = I; j = L [J]) Resume (j); resume (I );}}  Int  Main (){  While (Scanf ( "  % D  " , & N, & M )! = EOF) {head = CNT = 0  ; Memset (PRE, -1 , Sizeof  (Pre ));  For ( Int I = 0 ; I <m; I ++ ){  Int  X, Y; scanf (  "  % D  " , & X ,& Y); add_edge (x, y); add_edge (Y, x);} NN = 0 ; Mm = N; build (); Mi = INF; DFS (  0  ); Printf (  "  % D \ n  "  , Mi );}} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.