Cod sursa(job #2279368)

Utilizator AndreiDeltaBalanici Andrei Daniel AndreiDelta Data 9 noiembrie 2018 15:05:33
Problema Triplete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>
#define Dim 4100
using namespace std;
ifstream f("triplete.in");
ofstream g("triplete.out");
vector < int > Vf[Dim];
int N,M,a,b,Aux[Dim],cnt;
long long ans;
bool Mch[Dim][Dim];


int main()
{
    f>>N>>M;
    for(int i=1;i<=M;i++)
    {
        f>>a>>b;
        Mch[a][b]=1;
        Mch[b][a]=1;
        Vf[a].push_back(b);
        Vf[b].push_back(a);
    }
    for(int i=1;i<=N;i++)
    {
        cnt=0;
        for(unsigned int j=0;j<Vf[i].size();j++)
            Aux[++cnt]=Vf[i][j];

        for(int op=1;op<=cnt;op++)
            for(int l=op+1;l<=cnt;l++)
        if(Mch[Aux[op]][Aux[l]]) ans+=2;

    }
    g<<ans/6;
    return 0;
}