답안 #928457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928457 2024-02-16T12:21:51 Z TAhmed33 철인 이종 경기 (APIO18_duathlon) C++
10 / 100
62 ms 26824 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
vector <int> adj[MAXN];
int n, m;
int dep[MAXN], low[MAXN];
vector <int> adj2[MAXN];
int cnt, sze2;
long long ans;
vector <int> cur;
void dfs (int pos, int par, int tt) {
	dep[pos] = low[pos] = tt; cur.push_back(pos);
	sze2++;
	for (auto j : adj[pos]) {
		if (j == par) continue;
		if (dep[j]) {
			low[pos] = min(low[pos], dep[j]);
		} else {
			dfs(j, pos, tt + 1);
			low[pos] = min(low[pos], low[j]);
			if (low[j] >= dep[pos]) {
				++cnt;
				adj2[pos].push_back(n + cnt);
				while (adj2[n + cnt].empty() || adj2[n + cnt].back() != j) {
					adj2[n + cnt].push_back(cur.back());
					cur.pop_back();
				}
			}
		}
	}
}
int sze[MAXN];
void dfs2 (int pos, int par) {
	if (pos <= n) sze[pos] = 1;
	long long l = adj2[pos].size();
	for (auto j : adj2[pos]) {
		dfs2(j, pos);
		sze[pos] += sze[j];
		if (pos > n) {
			ans -= 1ll * sze[j] * (sze[j] - 1) * l;
		}
	}
	if (pos > n) {
		ans -= 1ll * (sze2 - sze[pos]) * (sze2 - sze[pos] - 1) * l;
	}
}
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) {
		if (!dep[i]) {
			sze2 = 0; cur.clear();
			dfs(i, -1, 0);
			ans += sze2 * (sze2 - 1) * (sze2 - 2);
			dfs2(i, -1);
		}
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 11868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 11868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 26824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 3 ms 11868 KB Output is correct
3 Correct 3 ms 12124 KB Output is correct
4 Correct 3 ms 12124 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 4 ms 12124 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 3 ms 12120 KB Output is correct
10 Correct 3 ms 12124 KB Output is correct
11 Correct 3 ms 11868 KB Output is correct
12 Correct 3 ms 11868 KB Output is correct
13 Correct 4 ms 11864 KB Output is correct
14 Correct 3 ms 11868 KB Output is correct
15 Correct 3 ms 12028 KB Output is correct
16 Correct 3 ms 11868 KB Output is correct
17 Correct 3 ms 11868 KB Output is correct
18 Correct 3 ms 11868 KB Output is correct
19 Correct 3 ms 12124 KB Output is correct
20 Correct 3 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 21432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 3 ms 12124 KB Output is correct
3 Correct 4 ms 11868 KB Output is correct
4 Incorrect 3 ms 11868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 21332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 11868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 11868 KB Output isn't correct
2 Halted 0 ms 0 KB -