Cod sursa(job #2043425)

Utilizator DianaVelciovVelciov Diana DianaVelciov Data 19 octombrie 2017 23:31:12
Problema Triplete Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int N_MAX = 4100;
int N, M, s = 0;
vector <int> G[N_MAX];

void solve(int node){
    for (int vecin : G[node])
        for (int vv : G[vecin])
            for (int last : G[vv])
                if (last == node){
                    s++;
                    break;
                }
}

int main(){
    in >> N >> M;
    for (int i = 1; i <= M; ++i){
        int x, y; in >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for (int i = 1; i <= N; ++i)
        solve(i);
    out << s/6 << '\n';
    in.close(); out.close();
    return 0;
}