| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
第100次提交留念。非常郁闷的2次AC。唉……第一次竟然没输出"Scenario #\n",WA的很茫然。
贴个Pascal代码(Ps: 现在用Pascal的越来越少了,估计没人能看懂,不过我写的很美观):
//===============================================
Program A_Bug_Life;
Const MaxN = 2005;
Var
Opp: Array[0..MaxN]Of LongInt;
Father: Array[0..MaxN]Of LongInt;
T, N, M: LongInt; i: LongInt; flag: Boolean;
//-----------------------------------------------
Function Find(x: LongInt): LongInt;
Begin
If Father[x] <> x Then
Father[x] := Find(Father[x]);
Find := Father[x];
End;
//-----------------------------------------------
Procedure Work(x, y: LongInt);
Var Fax, Fay, i, j: LongInt;
Begin
Fax := Find(x); Fay := Find(y);
If Fax = Fay Then Begin
flag := False; Exit;
End;
If (Opp[Fax] = Fay)And(Opp[Fay] = Fax) Then Exit;
If (Opp[Fax] = 0)And(Opp[Fay] = 0) Then Begin
Opp[Fax] := Fay; Opp[Fay] := Fax;
End Else If Opp[Fax] = 0 Then Begin
i := Find(Opp[Fay]);
If i <> Fax Then Father[Fax] := i; Opp[Fax] := Fay;
End Else If Opp[Fay] = 0 Then Begin
i := Find(Opp[Fax]);
If i <> Fay Then Father[Fay] := i; Opp[Fay] := Fax;
End Else Begin
i := Find(Opp[Fax]); j := Find(Opp[Fay]);
If Fax <> j Then Father[Fax] := j;
If Fay <> i Then Father[Fay] := i;
Opp[Fax] := Opp[Father[Fax]]; Opp[Fay] := Opp[Father[Fay]];
End;
End;
//-----------------------------------------------
Procedure Main;Var i, u, v: LongInt;
Begin
FillChar(Father, SizeOf(Father), 0);
FillChar(Opp, SizeOf(Opp), 0);
ReadLn(N, M); flag := True;
For i := 1 To N Do Father[i] := i;
For i := 1 To M Do Begin
ReadLn(u, v);
If flag Then Work(u, v);
End;
End;
//-----------------------------------------------
Begin
ReadLn(T);
For i := 1 To T Do Begin
Main;
WriteLn('Scenario #', i, ':');
If flag Then WriteLn('No suspicious bugs found!')
Else WriteLn('Suspicious bugs found!');
WriteLn;
End;
End.
//===============================================
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator