Cod sursa(job #752268)

Utilizator PetcuIoanPetcu Ioan Vlad PetcuIoan Data 28 mai 2012 11:31:10
Problema Triplete Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<stdio.h>
#include<assert.h>

#include<vector>
#include<algorithm>
#include<bitset>

using namespace std;

const int knmax = 4100;
bitset<knmax> aux, graph[knmax];
int verts, edges;

void read(){
  assert(freopen("triplete.in", "r", stdin));

  scanf("%d%d", &verts, &edges);

  for(int i = 1; i <= edges; ++i){
    int ver1, ver2;
    scanf("%d%d", &ver1, &ver2);
    graph[ver1][ver2] = graph[ver2][ver1] = 1;
  }

}

long long ans;

void solve(){
  for(int i = 1; i <= verts; ++i)
    for(int j = i + 1; j <= verts; ++j)
      if(graph[i][j]){
        aux = graph[i] & graph[j];
        ans = ans + aux.count();
      }
}

void write(){
  assert(freopen("triplete.out", "w", stdout));

  printf("%lld", ans / 3);
}

int main(){
  read();
  solve();
  write();
  return 0;
}