Cod sursa(job #1314060)

Utilizator vladrochianVlad Rochian vladrochian Data 11 ianuarie 2015 14:51:55
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
#include <bitset>
#include <vector>
using namespace std;

const int kMaxN = 4100;

ifstream fin("triplete.in");
ofstream fout("triplete.out");

int N, M, sol;
bitset<kMaxN> ad[kMaxN];
vector<int> G[kMaxN];
char buffer[12], *p;

void Parse(int &x) {
	x = 0;
	while (*p < '0')
		++p;
	while (*p >= '0')
		x = x * 10 + *(p++) - '0';
}
void Parse(int &x, int &y) {
	fin.getline(buffer, 12);
	p = buffer;
	Parse(x);
	Parse(y);
}

int main() {
	Parse(N, M);
	while (M--) {
		int x, y;
		Parse(x, y);
		if (x > y)
			swap(x, y);
		G[x].push_back(y);
		ad[x][y] = true;
	}
	for (int i = 1; i < N - 1; ++i)
		for (int j : G[i])
			sol += (ad[i] & ad[j]).count();
	fout << sol << "\n";
	return 0;
}