Cod sursa(job #867528)

Utilizator CrescentselectJicol Crescent Crescentselect Data 29 ianuarie 2013 20:01:55
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <iostream>
#include<fstream>
#include<vector>
#include <iterator>

using namespace std;

FILE *f = fopen("triplete.in","r");
ofstream g("triplete.out");

# define N 4096

vector<short> mat[N+1];

unsigned int n,m,rez;

void citire()
{
    int x,y;
    fscanf(f,"%d%d",&n,&m);
    for( unsigned int i=1;i<=m;i++)
    {
        fscanf(f,"%d%d",&x,&y);
        mat[x].push_back(y);
        mat[y].push_back(x);
    }
    for( unsigned int i=1;i<=n;i++)
    {
        sort(mat[i].begin(),mat[i].end());
    }
}
void proces()
{
    for( unsigned int i=1;i<=n-2;i++)
    {
        for( unsigned int j=0;j<mat[i].size();j++)
        {
            if((unsigned int)mat[i][j] > i) {
                for(unsigned int k=0;k<mat[mat[i][j]].size();k++)
                {
                    for( unsigned int l=j+1;l<mat[i].size();l++) {
                        if(mat[i][l] > mat[i][j] && mat[i][l] == mat[mat[i][j]][k])
                        {
                            rez++;
                            break;
                        }
                    }
                }
            }
        }
    }
    g<<rez;
}
int main()
{
    citire();

    proces();

    fclose(f);
    g.close();
    return 0;
}