Cod sursa(job #1217546)

Utilizator cojocarugabiReality cojocarugabi Data 7 august 2014 18:05:56
Problema Triplete Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
ifstream fi("triplete.in");
ofstream fo("triplete.out");
#define nmax 4100
typedef struct node{int x;node *next;} *nod;
nod S[nmax];
int main(void)
{
    int n,m;
    for (fi>>n>>m;m--;)
    {
       int x,y;
       fi>>x>>y;
       if (x>y) swap(x,y);
       nod p;
       p=new node;
       p->x=y;p->next=S[x];S[x]=p;
    }
    unsigned int R=0;
    for (int i=1;i<=n;++i)
        for (nod j=S[i];j;j=j->next)
            for (nod a=j->next;a;a=a->next)
    {
        int x=j->x,y=a->x;
        if (x>y) swap(x,y);
        for (nod p=S[x];p;p=p->next)
        if (p->x==y) {++R;break;}
    }
    fo<<R<<"\n";
    return 0;
}