Cod sursa(job #2274088)

Utilizator memecoinMeme Coin memecoin Data 1 noiembrie 2018 12:36:55
Problema Triplete Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
 
using namespace std;

int n, m;

bool a[4100][4100];

vector<int> g[4100];

int main() {
	freopen("triplete.in", "r", stdin);
	freopen("triplete.out", "w", stdout);

	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		a[x][y]++;
		a[y][x]++;

		if (x < y) {
			g[x].push_back(y);
		}
		else {
			g[y].push_back(x);
		}
	}

	int result = 0;

	for (int i = 1; i <= n; ++i) {

		for (auto j : g[i]) {
			for (int k = j + 1; k <= n; ++k) {
				if (a[i][k] && a[j][k]) {
					result++;
				}
			}
		}

	}

	printf("%d", result);

	return 0;
}