Cod sursa(job #1213506)

Utilizator rangerChihai Mihai ranger Data 28 iulie 2014 12:44:17
Problema Triplete Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<fstream>
#include<cstring>
using namespace std;
typedef struct cell
{
    int info;
    cell* next;
} *lista;
ifstream cin("triplete.in");
ofstream cout("triplete.out");
const int nmax=5000;
lista a[nmax],v;
int n,m,x,y,i,j,d[nmax],r=0,vf,ok;
int main()
{
    cin>>n>>m;
    for (i=1;i<=m;i++) cin>>x>>y, v=new cell, v->info=y, v->next=a[x], a[x]=v, v=new cell, v->info=x, v->next=a[y], a[y]=v;
    for (i=3;i<=n;i++)
    {
        vf=0;
        for (v=a[i];v;v=v->next)
            if (v->info<=i-1) d[++vf]=v->info;
        for (int k=1;k<vf;k++)
            for (int l=k+1;l<=vf;l++)
        {
            ok=0;
            for (v=a[d[k]];v;v=v->next)
            if (v->info==d[l]) {ok=1; break;}
            if (ok!=0) r++;
        }
    }
    cout<<r;
    return 0;
}