Cod sursa(job #2324993)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 21 ianuarie 2019 20:35:14
Problema Triplete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("triplete.in");
ofstream fout("triplete.out");

const int NMax = 4096;

vector <int> G[NMax + 5];

int N, M, x, y, Ans;

bool A[NMax + 5][NMax + 5];

void Read()
{
    fin >> N >> M;

    for(int i = 0; i < M; i++) {
        fin >> x >> y;

        G[x].push_back(y);
        G[y].push_back(x);

        A[x][y] = A[y][x] = true;
    }
}

void Solve_and_Print()
{
    for(int a = 1; a < N - 1; a++)
    {
        for(auto b : G[a])
            for(auto c : G[b])
            {
                if(a < b && b < c && A[a][c])
                    Ans++;
            }
    }

    fout << Ans << '\n';
}

int main()
{
    Read();
    Solve_and_Print();

    fin.close();
    fout.close();

    return 0;
}