Cod sursa(job #1217550)

Utilizator cojocarugabiReality cojocarugabi Data 7 august 2014 18:18:42
Problema Triplete Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string>
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];
char C[105];
int main(void)
{
    unsigned int n,m;
    for (fi>>n>>m;m--;)
    {
       int x=0,y=0;
       fi>>C;
       int A=0;
       while ('0'<=C[A] && C[A]<='9') x*=10,x+=C[A]-'0',++A;
       fi>>C;A=0;
       while ('0'<=C[A] && C[A]<='9') y*=10,y+=C[A]-'0',++A;
       if (x>y) swap(x,y);
       nod p;
       p=new node;
       p->x=y;p->next=S[x];S[x]=p;
    }
    unsigned long long 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;
}