Submission #928458

# Submission time Handle Problem Language Result Execution time Memory
928458 2024-02-16T12:24:14 Z TAhmed33 Duathlon (APIO18_duathlon) C++
0 / 100
46 ms 17508 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);
	}
	memset(dep, -1, sizeof(dep));
	for (int i = 1; i <= n; i++) {
		if (-1 == dep[i]) {
			sze2 = 0; cur.clear();
			dfs(i, -1, 0);
			ans += sze2 * (sze2 - 1) * (sze2 - 2);
			dfs2(i, -1);
		}
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 11864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 11864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 17028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 11868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 17508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 11864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 17272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 11864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 11864 KB Output isn't correct
2 Halted 0 ms 0 KB -