求一下时间复杂度?
  • 板块灌水区
  • 楼主封禁用户
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/30 08:50
  • 上次更新2024/8/30 12:51:30
查看原帖
求一下时间复杂度?
1001535
封禁用户楼主2024/8/30 08:50
#include <bits/stdc++.h>
#define p pair
#define se set
#define um unordered_map
using namespace std;
#define int long long
const int N = 5e4 + 5, X = 1002, MOD = 1e6 + 2;
int n, m, u[N], v[N], w[N], f[N], ans;
int read() {
	int t = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		t = t * 10 + c - '0';
		c = getchar();
	}
	return t * f;
}
void write(int x) {
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + '0');
}
struct h {
	int operator()(p<int, int> x) const {
		return (x.first + x.second * X % MOD) % MOD;
	};
};
um<p<int, int>, se<int>, h> e;
void change(int &x, int &y) {
	if (f[x] > f[y]) swap(x, y);
	else if (f[x] == f[y] && x > y) swap(x, y);
}
void cu(set<int> a, set<int> b, set<int> c) {
	for (int i : a) if (b.count(i) && c.count(i)) ans++;
}
signed main() {
	n = read() , m = read();
	for (int i = 1; i <= m; i++) {
	 u[i] = read() , v[i] = read() , w[i] = read(), f[u[i]]++, f[v[i]]++, f[w[i]]++;
	}
	for (int i = 1; i <= m; i++) {
		change(u[i], v[i]), change(u[i], w[i]), change(v[i], w[i]);
	}
	for (int i = 1; i <= m; i++) {
		e[ {u[i], v[i]}].insert(w[i]);
	}
	for (int i = 1; i <= m; i++) {
		cu(e[ {u[i], v[i]}], e[ {u[i], w[i]}], e[ {v[i], w[i]}]);
	}
    write(ans);
	return 0;
}
2024/8/30 08:50
加载中...