Cod sursa(job #35453)

Utilizator pitradaPit-Rada Ionel-Vasile pitrada Data 22 martie 2007 06:33:17
Problema Triplete Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include<fstream>
using namespace std;

fstream fin,fout;

long n,m,t,p,i,j,u,v;
char a[2049][4097];
int b[65536],c[65536];

int main(void)
{
fin.open("triplete.in",ios::in);
fout.open("triplete.out",ios::out);
fin>>n>>m;
p=2048; if (n<2048)p=n;
for (i=1;i<=p;i++)
  for (j=1;j<=n;j++)
   a[i][j]=0;
for (i=0;i<m;i++)
  {
  fin>>u>>v;
  if (u<=p) a[u][v]=1;
  if (v<=p) a[v][u]=1;
  b[i]=u; c[i]=v;
  }
t=0;

for (i=0;i<m;i++)
  {
  u=b[i];v=c[i];
  for (j=1;j<=p;j++)
    if (a[j][u]&&a[j][v])
      t++;
  }
if (p<n)
{
for (i=1;i<=n-2048;i++)
  for (j=1;j<=n;j++)
   a[i][j]=0;
for (i=0;i<m;i++)
  {
  u=b[i];v=c[i];
  if (u-2048>0) a[u-2048][v]=1;
  if (v-2048>0) a[v-2048][u]=1;
  }
for (i=0;i<m;i++)
  {
  u=b[i];v=c[i];
  for (j=1;j<=n-2048;j++)
    if (a[j][u]&&a[j][v])
      t++;
  }
}
t=t/3;
fout<<t<<endl;
fin.close();
fout.close();
return 0;
}