Cod sursa(job #3231492)

Utilizator DobraVictorDobra Victor Ioan DobraVictor Data 26 mai 2024 20:20:37
Problema Triplete Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 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) {
			adj[x].push_back(y);
		} else {
			adj[y].push_back(x);
		}
		mat[x][y] = 1;
		mat[y][x] = 1;
	}

	int32_t count = 0;
	for(int32_t i = 0; i != n; ++i) {
		for(int32_t j : adj[i]) {
			for(int32_t k = j + 1; k != n; ++k) {
				if(mat[k][i] && mat[k][j])
					++count;
			}
		}
	}

	fout << count;

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

	return 0;
}