Cod sursa(job #2676309)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 23 noiembrie 2020 22:19:03
Problema Triplete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;

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

const int nmax = 4100, mmax = 66000;
int n, m;
pair <int, int> edge[mmax];
bitset <nmax> mat[nmax];
int main(){
    fin >> n >> m;
    for (int i = 1; i <= m; ++i){
        int x, y;
        fin >> x >> y;
        edge[i] = {x, y};
        mat[x][y] = mat[y][x] = 1;
    }
    long long answer = 0;
    for (int i = 1; i <= m; ++i){
        int x = edge[i].first, y = edge[i].second;
        answer = 1LL * answer + (mat[x] & mat[y]).count();
    }
    fout << answer / 3 << "\n";
    fin.close();
    fout.close();
    return 0;
}