Submission #252390

# Submission time Handle Problem Language Result Execution time Memory
252390 2020-07-25T12:41:47 Z Saboon Duathlon (APIO18_duathlon) C++14
31 / 100
139 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 * a[v] * sz2[u] * (sz[rt[v]] - sz2[u] - a[v]);
		}
	}
	if (par != -1)
		answer += 1ll * a[v] * (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 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 27512 KB Output is correct
2 Correct 77 ms 27384 KB Output is correct
3 Correct 91 ms 25464 KB Output is correct
4 Correct 91 ms 26744 KB Output is correct
5 Correct 82 ms 23672 KB Output is correct
6 Correct 91 ms 24312 KB Output is correct
7 Correct 90 ms 23420 KB Output is correct
8 Correct 99 ms 24184 KB Output is correct
9 Correct 133 ms 22648 KB Output is correct
10 Correct 126 ms 23032 KB Output is correct
11 Correct 90 ms 21624 KB Output is correct
12 Correct 71 ms 21496 KB Output is correct
13 Correct 81 ms 21624 KB Output is correct
14 Correct 69 ms 21496 KB Output is correct
15 Correct 62 ms 21240 KB Output is correct
16 Correct 53 ms 21052 KB Output is correct
17 Correct 12 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 10 ms 16768 KB Output is correct
21 Correct 12 ms 16768 KB Output is correct
22 Correct 14 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14592 KB Output is correct
2 Correct 10 ms 14592 KB Output is correct
3 Correct 8 ms 14592 KB Output is correct
4 Correct 9 ms 14464 KB Output is correct
5 Correct 8 ms 14592 KB Output is correct
6 Correct 9 ms 14592 KB Output is correct
7 Correct 10 ms 14612 KB Output is correct
8 Correct 17 ms 14544 KB Output is correct
9 Correct 8 ms 14592 KB Output is correct
10 Correct 9 ms 14592 KB Output is correct
11 Correct 8 ms 14592 KB Output is correct
12 Correct 8 ms 14592 KB Output is correct
13 Correct 9 ms 14592 KB Output is correct
14 Correct 12 ms 14592 KB Output is correct
15 Correct 9 ms 14592 KB Output is correct
16 Correct 8 ms 14592 KB Output is correct
17 Correct 8 ms 14592 KB Output is correct
18 Correct 8 ms 14592 KB Output is correct
19 Correct 8 ms 14592 KB Output is correct
20 Correct 8 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 23416 KB Output is correct
2 Correct 88 ms 23416 KB Output is correct
3 Correct 87 ms 23420 KB Output is correct
4 Correct 105 ms 23416 KB Output is correct
5 Correct 115 ms 23416 KB Output is correct
6 Correct 139 ms 27384 KB Output is correct
7 Correct 109 ms 26104 KB Output is correct
8 Correct 129 ms 25336 KB Output is correct
9 Correct 122 ms 24568 KB Output is correct
10 Correct 83 ms 23416 KB Output is correct
11 Correct 82 ms 23416 KB Output is correct
12 Correct 95 ms 23416 KB Output is correct
13 Correct 90 ms 23380 KB Output is correct
14 Correct 107 ms 23160 KB Output is correct
15 Correct 74 ms 22904 KB Output is correct
16 Correct 49 ms 21624 KB Output is correct
17 Correct 61 ms 23920 KB Output is correct
18 Correct 61 ms 23920 KB Output is correct
19 Correct 62 ms 23916 KB Output is correct
20 Correct 62 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14592 KB Output is correct
2 Correct 9 ms 14592 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 85 ms 23416 KB Output is correct
2 Correct 100 ms 23292 KB Output is correct
3 Incorrect 97 ms 22156 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 14464 KB Output isn't correct
2 Halted 0 ms 0 KB -