Cod sursa(job #3231493)

Utilizator DobraVictorDobra Victor Ioan DobraVictor Data 26 mai 2024 20:23:35
Problema Triplete Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <stdint.h>
#include <vector>
#include <bitset>

const int32_t MAX_N = 4096;

std::vector<int32_t> adj[MAX_N];
std::bitset<MAX_N> mat[MAX_N];

int main() {
	std::ifstream fin("triplete.in");
	std::ofstream fout("triplete.out");

	int32_t n, m;
	fin >> n >> m;
	for(int32_t i = 0; i != m; ++i) {
		int32_t x, y;
		fin >> x >> y;
		--x; --y;

		if(x > y) {
			int32_t aux = x;
			x = y;
			y = aux;
		}

		adj[x].push_back(y);
		mat[x][y] = 1;
	}

	int32_t count = 0;
	for(int32_t i = 0; i != n; ++i)
		for(int32_t j : adj[i])
			count += (mat[i] & mat[j]).count();

	fout << count;

	fin.close();
	fout.close();

	return 0;
}