1506 Messenger _wikioi

Source: Internet
Author: User
This algorithm is simple, but timeout: var   n,m,i,x,y:longint;   f:array[1..1000,1..1000] of Boolean; Procedure Floyd; var   k,i,j:longint; Begin   for K:=1 to N does     for I:=1 to N does       for J:=1 to N do       &N Bsp F[I,J]:=F[I,J] or (f[i,k) and f[k,j]); End Begin   Fillchar (f,sizeof (f), false);   Read (n,m);   for I:=1 to M do     begin       read (x,y);       F[x,y]:=true;     END;   Floyd;   for I:=1 to n do     if f[i,i] then Writeln (' T ')     else write (' F '); End. The simple deep search still timed out: var   n,m,a,b,i,d:longint;   f:array[1..1000,1..1000] of Boolean;   used:array[1..1000] of Boolean;   Flag:boolean; Procedure Search (X:longint;var d:longint); var   k:longint; Begin   if (x=i) and (d>0) and (not flag) then     begin       writeln (' T ');       Flag:=true;       exit;   &NBsp End   for K:=1 to N does     if (F[x,k]) and (not used[k]) then       begin       & nbsp Used[k]:=true;         Inc. (d);         search (k,d);         Used[k]:=false; {Remove this sentence or timeout, only 8 points, do not backtrack}       end; End Begin   Fillchar (f,sizeof (f), false);   Read (n,m);   for I:=1 to M do     begin       read (A,B);       F[a,b]:=true;     END;   for I:=1 to n do     begin       Fillchar (used,sizeof (used), false);       Flag:=false;       d:=0;       Search (i,d);       If not flag then Writeln (' F ');     END; End. Weakly weak ground: Still use adjacent chain table to keep the edge ...

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.