Cod sursa(job #755876)

Utilizator vendettaSalajan Razvan vendetta Data 7 iunie 2012 22:45:49
Problema Triplete Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <iostream>
#include <set>
#include <iostream>

using namespace std;

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

#define nmax 4099

int n, m;
typedef set<int>::iterator it;
set<int> s[nmax];

void citeste(){

    f >> n >> m;
    for(int i=1; i<=m; i++){
        int x, y;
        f >> x >> y;
        s[x].insert(y);
        s[y].insert(x);
    }

}

void rezolva(){

    int rez = 0;

    for(int i=1; i<=n; i++){
        for(it j=s[i].lower_bound(i); j!=s[i].end(); j++){
            for(it k=s[*j].lower_bound(*j); k!=s[*j].end(); k++){
                if (s[*k].find(i) != s[*k].end() ) ++rez;
            }
        }
    }

    g << rez << "\n";

    cout << rez << "\n";

}

int main(){

    citeste();
    rezolva();

    f.close();
    g.close();

    return 0;

}