Cod sursa(job #2137900)

Utilizator SenibelanMales Sebastian Senibelan Data 21 februarie 2018 09:16:31
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <bitset>
#include <vector>

using namespace std;

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

int N, M;
const int NMAX = 4100;
bitset <NMAX> friendships[NMAX];
vector <int> G[NMAX];

void Read(){
    in >> N >> M;
    for(int i = 1; i <= M; ++i){
        int a, b;
        in >> a >> b;
        G[a].push_back(b);

        friendships[a][b] = 1;
        friendships[b][a] = 1;
    }
}

void SolveAndPrint(){
    int sol = 0;
    for(int i = 1; i <= N; ++i){
        for(int j = 0; j < G[i].size(); ++j){
            sol += (friendships[i] & friendships[G[i][j]]).count();
        }
    }
    out << sol / 3 << "\n";
}


int main(){
    Read();
    SolveAndPrint();
    return 0;
}