Pagini recente » Cod sursa (job #189958) | Cod sursa (job #1225048) | Cod sursa (job #63884) | Cod sursa (job #188554) | Cod sursa (job #867528)
Cod sursa(job #867528)
#include <iostream>
#include<fstream>
#include<vector>
#include <iterator>
using namespace std;
FILE *f = fopen("triplete.in","r");
ofstream g("triplete.out");
# define N 4096
vector<short> mat[N+1];
unsigned int n,m,rez;
void citire()
{
int x,y;
fscanf(f,"%d%d",&n,&m);
for( unsigned int i=1;i<=m;i++)
{
fscanf(f,"%d%d",&x,&y);
mat[x].push_back(y);
mat[y].push_back(x);
}
for( unsigned int i=1;i<=n;i++)
{
sort(mat[i].begin(),mat[i].end());
}
}
void proces()
{
for( unsigned int i=1;i<=n-2;i++)
{
for( unsigned int j=0;j<mat[i].size();j++)
{
if((unsigned int)mat[i][j] > i) {
for(unsigned int k=0;k<mat[mat[i][j]].size();k++)
{
for( unsigned int l=j+1;l<mat[i].size();l++) {
if(mat[i][l] > mat[i][j] && mat[i][l] == mat[mat[i][j]][k])
{
rez++;
break;
}
}
}
}
}
}
g<<rez;
}
int main()
{
citire();
proces();
fclose(f);
g.close();
return 0;
}