Cod sursa(job #7267)

Utilizator VmanDuta Vlad Vman Data 21 ianuarie 2007 13:16:29
Problema Triplete Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 1, Clasa a 10-a Marime 1.01 kb
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

long t[4097], x, y, i, j, k;
int  a[201][20];
long long tot, n, m;
FILE *f;

int main()
{
      f=fopen("triplete.in", "r");
      fscanf(f, "%ld%ld\n", &n, &m);
      if (n>200)
      {
      memset(t, 0, sizeof(t));
      for (i=0; i<m; ++i)
	  {
	  fscanf(f, "%ld%ld\n", &x, &y);
	  ++t[x];
	  ++t[y];
	  }
      fclose(f);
      f = fopen("triplete.out", "w");
      tot = 0;
      for (i=1; i<=n; ++i)
	  tot += t[i] * (n - t[i] - 1);
      tot = ((n * (n - 1) * (n - 2)) / 3 - tot) / 2;
      fprintf(f, "%lld", tot);
      fclose(f);
      }
      else {
	memset(a,0,sizeof(a));
	for (i=0;i<m;++i)
		{
		fscanf(f,"%ld%ld\n",&x,&y);
		a[x][y]=1;
		a[y][x]=1;
		}
       fclose(f);
       f=fopen("triplete.out","w");
       tot=0;
       for (i=1;i<=n;++i)
	for (j=1;j<=n;++j)
		for (k=1;k<=n;++k)
			if ((a[i][j])&&(a[i][k])&&(a[j][k])) ++tot;
       fprintf(f,"%lld",tot/6);
       fclose(f);
       }
      return 0;
}