Pagini recente » Cod sursa (job #2618233) | Cod sursa (job #16230) | Cod sursa (job #425753) | Cod sursa (job #592926) | Cod sursa (job #272404)
Cod sursa(job #272404)
#include<stdio.h>
#include<string.h>
#define Nmax 4100
#define Mmax 6600
FILE *fin=fopen("triplete.in","r"),
*fout=fopen("triplete.out","w");
int N,M,rez;
char *A[Nmax];
struct nod{int inf;nod* next;};
typedef nod* lista;
lista L[Nmax];
int main(){
fscanf(fin,"%d %d",&N,&M);
for(int i=1;i<=N;i++)
A[i]=new char[N];
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
A[i][j]=0;
for(int i=1;i<=M;i++){
int x,y;
fscanf(fin,"%d %d",&x,&y);
A[x][y]=A[y][x]=1;
lista aux=new nod;
aux->inf=x;
aux->next=L[y];
L[y]=aux;
}
for(int i=1;i<=N;i++)
for(lista p=L[i];p;p=p->next)
for(int j=1;j<=N;j++)
if(A[i][j] && A[p->inf][j])
++rez;
fprintf(fout,"%d\n",rez/3);
fclose(fin);
fclose(fout);
return 0;
}