Cod sursa(job #2567753)

Utilizator andreighinea1Ghinea Andrei-Robert andreighinea1 Data 3 martie 2020 18:42:58
Problema Triplete Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define nmax 4100
#define mmax 65550

using namespace std;

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

struct muchie{
    int x,y;
} v[mmax];

int n,m,i,j,x,y,sum;
bool a[nmax][nmax];

inline bool cmp(muchie a,muchie b){
    if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}

int main()
{
    f >> n >> m;
    for(i=1;i<=m;++i){
        f >> x >> y;
        v[i].x=x;
        v[i].y=y;
        a[x][y]=a[y][x]=true;
    }
    sort(v+1,v+1+m,cmp);

    for(i=1;i<=m;++i){
        for(j=i+1; j<=m && v[i].x==v[j].x; ++j){
            if(a[v[i].y][v[j].y])
                ++sum;
        }
    }

    o << sum << '\n';

    return 0;
}