답안 #405060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405060 2021-05-15T16:25:52 Z BERNARB01 철인 이종 경기 (APIO18_duathlon) C++17
8 / 100
36 ms 3532 KB
#include <bits/stdc++.h>

using namespace std;

struct dsu {
	int nCC;
	vector<int> pr, sz, rank, edges;
	dsu(int n) {
		nCC = n;
		pr.resize(n);
		sz.assign(n, 1);
		edges.assign(n, 0);
		rank.assign(n, 1);
		iota(pr.begin(), pr.end(), 0);
	}
	int fnd(int u) {
		if (u == pr[u]) {
			return u;
		}
		pr[u] = fnd(pr[u]);
		return pr[u];
	}
	bool unate(int u, int v) {
		u = fnd(u); v = fnd(v);
		if (u == v) {
			edges[u]++;
			return false;
		}
		--nCC;
		if (rank[u] > rank[v]) {
			swap(u, v);
		}
		pr[u] = v;
		rank[v] += (rank[u] == rank[v]);
		sz[v] += sz[u];
		edges[v] += 1 + edges[u];
		return true;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	dsu se(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		se.unate(u, v);
	}
	vector<int> vis(n, 0);
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		int P = se.fnd(i);
		if (!vis[P]) {
			vis[P] = 1;
			if (se.sz[P] > 2) {
				if (se.edges[P] == se.sz[P]) {
					ans += se.sz[P] * 1LL * (se.sz[P] - 1) * (se.sz[P] - 2);
				} else {
					ans += se.sz[P] * 1LL * (se.sz[P] - 1) * (se.sz[P] - 2) / 3;
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3416 KB Output is correct
2 Correct 30 ms 3416 KB Output is correct
3 Correct 32 ms 3396 KB Output is correct
4 Correct 29 ms 3504 KB Output is correct
5 Correct 28 ms 3412 KB Output is correct
6 Correct 28 ms 3416 KB Output is correct
7 Correct 28 ms 3396 KB Output is correct
8 Correct 28 ms 3408 KB Output is correct
9 Correct 36 ms 3408 KB Output is correct
10 Correct 30 ms 3512 KB Output is correct
11 Correct 26 ms 3280 KB Output is correct
12 Correct 27 ms 3408 KB Output is correct
13 Correct 28 ms 3160 KB Output is correct
14 Correct 22 ms 3152 KB Output is correct
15 Correct 18 ms 2860 KB Output is correct
16 Correct 17 ms 2908 KB Output is correct
17 Correct 2 ms 2252 KB Output is correct
18 Correct 2 ms 2252 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 2 ms 2252 KB Output is correct
21 Correct 3 ms 2252 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 3532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 3412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -