Submission #252388

# Submission time Handle Problem Language Result Execution time Memory
252388 2020-07-25T12:21:31 Z Saboon Duathlon (APIO18_duathlon) C++14
31 / 100
147 ms 27512 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 20;
const int mod = 1e9 + 7;

vector<int> g[maxn], t[maxn];
int dw[maxn], h[maxn], rt[maxn], a[maxn], sz[maxn];
bool visited[maxn];
int sz2[maxn];
ll answer = 0;

void dfs2(int v, int par = -1){
	sz2[v] = a[v];
	for (auto u : t[v]){
		if (u != par){
			dfs2(u, v);
			sz2[v] += sz2[u];
			answer += 1ll * sz2[u] * (sz[rt[v]] - sz2[u] - a[v]);
		}
	}
	if (par != -1)
		answer += 1ll * (sz2[v] - a[v]) * (sz[rt[v]] - sz2[v]);
}

int dfs(int v, int root){
	rt[v] = root;
	visited[v] = true;
	int ret = h[v];
	sz[v] = 1;
	dw[v] = v;
	a[v] = 1;
	for (auto u : g[v]){
		if (!visited[u]){
			h[u] = h[v] + 1;
			int k = dfs(u, root);
			sz[v] += sz[u];
			if (k <= h[v]){
				a[v] = a[u];
				dw[v] = dw[u];
			}
			ret = min(ret, k);
		}
		else if (h[u] < h[v] - 1){
			dw[v] = v;
			a[v] = h[v] - h[u] + 1;
			ret = h[u];
		}
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int v, u;
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for (int v = 1; v <= n; v++)
		if (!visited[v])
			dfs(v, v);
	for (int i = 1; i <= n; i++)
		for (auto j : g[i])
			if (dw[i] != dw[j])
				t[dw[i]].push_back(dw[j]);
	for (int v = 1; v <= n; v++)
		if (h[v] == 0)
			dfs2(dw[v]);
	for (int v = 1; v <= n; v++)
		if (dw[v] == v and a[v] >= 3)
			answer -= 1ll*a[v]*(a[v]-1)*(a[v]-2);
	for (int f = 1; f <= n; f++){
		if (a[dw[f]] == 1)
			continue;
		int subsz = 1;
		for (auto u : g[f]){
			if (h[u] == h[f]+1 and dw[u] != dw[f])
				subsz += sz[u];
			if (h[u] == h[f]-1 and dw[u] != dw[f])
				subsz += (sz[rt[f]] - sz[f]);
		}
		int outsz = sz[rt[f]] - subsz;
		answer += 2ll * (a[dw[f]]-1) * (outsz-1);
	}
	cout << answer << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 27512 KB Output is correct
2 Correct 83 ms 27512 KB Output is correct
3 Correct 147 ms 25464 KB Output is correct
4 Correct 106 ms 26616 KB Output is correct
5 Correct 102 ms 23672 KB Output is correct
6 Correct 107 ms 24440 KB Output is correct
7 Correct 118 ms 23416 KB Output is correct
8 Correct 118 ms 24056 KB Output is correct
9 Correct 112 ms 22648 KB Output is correct
10 Correct 110 ms 23160 KB Output is correct
11 Correct 96 ms 21624 KB Output is correct
12 Correct 107 ms 21496 KB Output is correct
13 Correct 81 ms 21664 KB Output is correct
14 Correct 109 ms 21496 KB Output is correct
15 Correct 63 ms 21240 KB Output is correct
16 Correct 63 ms 20984 KB Output is correct
17 Correct 11 ms 16768 KB Output is correct
18 Correct 12 ms 16896 KB Output is correct
19 Correct 11 ms 16768 KB Output is correct
20 Correct 16 ms 16768 KB Output is correct
21 Correct 14 ms 16768 KB Output is correct
22 Correct 14 ms 16768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 14592 KB Output is correct
2 Correct 8 ms 14568 KB Output is correct
3 Correct 12 ms 14592 KB Output is correct
4 Correct 10 ms 14568 KB Output is correct
5 Correct 14 ms 14592 KB Output is correct
6 Correct 10 ms 14592 KB Output is correct
7 Correct 9 ms 14568 KB Output is correct
8 Correct 8 ms 14592 KB Output is correct
9 Correct 8 ms 14592 KB Output is correct
10 Correct 11 ms 14592 KB Output is correct
11 Correct 9 ms 14592 KB Output is correct
12 Correct 10 ms 14592 KB Output is correct
13 Correct 10 ms 14592 KB Output is correct
14 Correct 9 ms 14568 KB Output is correct
15 Correct 11 ms 14592 KB Output is correct
16 Correct 10 ms 14592 KB Output is correct
17 Correct 12 ms 14592 KB Output is correct
18 Correct 11 ms 14592 KB Output is correct
19 Correct 13 ms 14592 KB Output is correct
20 Correct 13 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 23444 KB Output is correct
2 Correct 124 ms 23396 KB Output is correct
3 Correct 103 ms 23392 KB Output is correct
4 Correct 86 ms 23416 KB Output is correct
5 Correct 93 ms 23416 KB Output is correct
6 Correct 107 ms 27384 KB Output is correct
7 Correct 117 ms 25976 KB Output is correct
8 Correct 114 ms 25336 KB Output is correct
9 Correct 110 ms 24568 KB Output is correct
10 Correct 94 ms 23432 KB Output is correct
11 Correct 119 ms 23376 KB Output is correct
12 Correct 92 ms 23416 KB Output is correct
13 Correct 94 ms 23416 KB Output is correct
14 Correct 83 ms 23160 KB Output is correct
15 Correct 97 ms 23032 KB Output is correct
16 Correct 54 ms 21628 KB Output is correct
17 Correct 66 ms 23920 KB Output is correct
18 Correct 66 ms 23916 KB Output is correct
19 Correct 71 ms 23916 KB Output is correct
20 Correct 68 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14592 KB Output is correct
2 Correct 9 ms 14508 KB Output is correct
3 Incorrect 11 ms 14592 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 23416 KB Output is correct
2 Correct 109 ms 23416 KB Output is correct
3 Incorrect 116 ms 22264 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14440 KB Output isn't correct
2 Halted 0 ms 0 KB -