Cod sursa(job #12122)

Utilizator bigsarpeadrian bigsarpe Data 2 februarie 2007 22:13:17
Problema Triplete Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.91 kb
{$q-,r-,s-,d-,i-}
const maxn=4096;maxbuc=maxn div 16;zero=ord('0');
var t:Text;
   Pre:Array[0..1 shl 16]of longint;
   X,Y:array[0..1 shl 16]of longint;
   V:Array[0..maxn,0..maxbuc]of word;
   sol,i,j,k,n,m:longint;s:string;
begin
   for i:=0 to 1 shl 16 do for j:=0 to 15 do inc(pre[i],(i shr j)and 1);
   assign(t,'triplete.in');reset(T);readln(t,n,m);
   for i:=1 to M do
   begin
      readln(T,s);
      for j:=1 to length(s) do if s[j]=' ' then break
          else X[i]:=X[i]*10+ord(s[j])-zero;
      for k:=j+1 to length(s) do y[i]:=y[i]*10+ord(s[k])-zero;
      dec(X[i]);dec(y[i]);
      V[X[i],Y[i]shr 4]:=V[X[i],Y[i]shr 4]or(1 shl (Y[i]and 15));
      V[Y[i],X[i]shr 4]:=V[Y[i],X[i]shr 4]or(1 shl (X[i]and 15));
   end;
   close(T);
   for j:=1 to M do for i:=0 to maxbuc do
      inc(sol,Pre[V[X[j],i]and V[Y[j],i]]);
   assign(T,'triplete.out');rewrite(T);writeln(T,sol div 3);close(T);
end.