답안 #337379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337379 2020-12-20T11:38:10 Z ttnhuy313 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
139 ms 34284 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int N = 2e5 + 5;
int n, m, tin[N], low[N], dfsTime, biCount, biComp[N], isCut[N], sz[N], res, cutsum[N], subSize[N];
vector <int> adj[N], include[N], near[N];
stack <int> S;

void dfs(int u, int pre) {
	tin[u] = low[u] = ++dfsTime;
	S.push(u);
	int nchild = 0;
	for (int v : adj[u]) {
		if (v == pre) continue;
		nchild++;
		if (!tin[v]) {
			dfs(v, u);
			if (low[v] >= tin[u]) {
				isCut[u] = 1;
				biCount++;
				while (S.top() != u) {
					int v = S.top();
					S.pop();
					include[biCount].push_back(v);
					biComp[v] = biCount;
				}
				include[biCount].push_back(u);
			}
			low[u] = min(low[u], low[v]);
		} else low[u] = min(low[u], tin[v]);
	}
	if (pre == -1) {
		isCut[u] = (nchild > 1);
	}
}

void dfs2(int u, int pre) {
	subSize[u] = sz[u];
	for (int v : near[u]) {
		if (v == pre) continue;
		dfs2(v, u);
		subSize[u] += subSize[v];
	}
	if (u > n) {
		int bf = 0, tmp = 0;
		if (~pre) bf = n - subSize[u];
		// cerr << bf << endl;
		for (int v : near[u]) {
			if (v == pre) continue;
			int cur = sz[v] - 1;
			// cerr << "	" << cur << ' ' << cur * bf << endl;
			tmp += cur * bf;
			bf += cur;
		}
		res -= tmp * 2;
		return;
	}
	if (u > n || cutsum[u] < 2) return;
	int bf = 0, tmp = 0;
	if (~pre) bf = n - subSize[u];
	for (int v : near[u]) {
		if (v == pre) continue;
		int cur = subSize[v] - 1;
		tmp += cur * bf * (sz[u] + cutsum[u] - 2);
		bf += cur;
	}
	res = res + (tmp * 2);
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, -1);
	for (int i = 1; i <= biCount; ++i) {
		sz[i] = include[i].size();
		res += sz[i] * (sz[i] - 1) * (sz[i] - 2);
		res += (n - sz[i]) * (sz[i] - 1) * (sz[i] - 1) * 2;
		for (int u : include[i]) if (isCut[u]) {
			cutsum[i]++;
			near[n + u].push_back(i);
			near[i].push_back(n + u);
		}
	}
	dfs2(1, -1);
	cout << res << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 32620 KB Output is correct
2 Correct 91 ms 32620 KB Output is correct
3 Incorrect 78 ms 26988 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 14720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 136 ms 34156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 14700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 139 ms 34284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 14444 KB Output isn't correct
2 Halted 0 ms 0 KB -