Submission #712202

# Submission time Handle Problem Language Result Execution time Memory
712202 2023-03-18T11:32:14 Z Radin_Zahedi2 Duathlon (APIO18_duathlon) C++17
49 / 100
159 ms 22268 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
//#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;


int n, m;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
vector<int> adj1[N];
bool mark[N];
int h[N];
int par[N];
int up[N];

vector<int> adj2[N + M];
bool mark2[N + M];

int block[N];
int bcnt[N];

int len[N + M];
int par2[N + M];
int total[N + M];


int mull(int a, int b) {
	return (1ll * a * b) % mod;
}

void init() {
}

void input() {
	cin >> n >> m;

	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
//		u = i; v = i + 1;

		adj1[u].pb(v);
		adj1[v].pb(u);
	}
}

void dfshp(int u) {
	mark[u] = true;

	for (auto v : adj1[u]) {
		if (!mark[v]) {
			h[v] = h[u] + 1;
			par[v] = u;
			dfshp(v);
		}
	}
}

void dfsup(int u) {
	mark[u] = true;

	up[u] = h[u];
	for (auto v : adj1[u]) {
		if (!mark[v]) {
			dfsup(v);
			up[u] = min(up[u], up[v]);
		}
		else {
			up[u] = min(up[u], h[v]);
		}
	}
}

void dfsbd(int u) {
	mark[u] = true;

	for (auto v : adj1[u]) {
		if (!mark[v]) {
			if (up[v] == h[u]) {
				block[v] = v;
				bcnt[v] = 1;
			}
			else {
				block[v] = block[u];
			}

			dfsbd(v);
		}
	}
}

void dfslen(int u) {
	if (u <= n) {
		len[u] = bcnt[u];
	}
	else {
		len[u] = 1;
	}

	for (auto v : adj2[u]) {
		if (v != par2[u]) {
			par2[v] = u;
			dfslen(v);
			len[u] += len[v] - 1;
		}
	}
}

void dfstotal(int u, const int x) {
	total[u] = x;

	for (auto v : adj2[u]) {
		if (v != par2[u]) {
			dfstotal(v, x);
		}
	}
}

void solve() {
	vector<int> roots;

	fill(mark + 1, mark + n + 1, false);
	for (int u = 1; u <= n; u++) {
		if (!mark[u]) {
			dfshp(u);
			roots.pb(u);
		}
	}

	fill(mark + 1, mark + n + 1, false);
	for (auto r : roots) {
		if (!mark[r]) {
			dfsup(r);
		}
	}

	fill(mark + 1, mark + n + 1, false);
	for (auto r : roots) {
		if (!mark[r]) {
			dfsbd(r);
		}
	}


	for (int u = 1; u <= n; u++) {
		bcnt[block[u]]++;
	}
	bcnt[0] = 0;


	for (int u = 1; u <= n; u++) {
		bool cut = false;
		for (auto v : adj1[u]) {
			if (par[v] == u && block[v] == v) {
				cut = true;
			}
		}

		if (cut) {
			adj2[block[u]].pb(u + n);
			adj2[u + n].pb(block[u]);
		}


		if (block[u] == u) {
			adj2[block[u]].pb(par[u] + n);
			adj2[par[u] + n].pb(block[u]);
		}
	}


	int ans = 0;
	for (auto r : roots) {
		dfslen(r + n);
		dfstotal(r + n, len[r + n]);

		ans += mull(len[r + n], mull(len[r + n] - 1, len[r + n] - 2));
	}

	for (int u = 1; u <= n; u++) {
		if (!len[u]) {
			continue;
		}

		for (auto v : adj2[u]) {
			if (par2[u] != v) {
				ans -= mull(bcnt[u] - 1, mull(len[v], len[v] - 1));
				ans %= mod;
			}
		}

		ans -= mull(bcnt[u] - 1, mull(total[u] - len[u] + 1, total[u] - len[u]));
		ans %= mod;
	}

	ans += mod;
	ans %= mod;
	cout << ans;
}

void output() {
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int number_of_testcases = 1;
	//cin >> number_of_testcases;
	while (number_of_testcases--) {
		init();

		input();

		solve();

		output();
	}

	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9664 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9664 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 8 ms 9684 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9648 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 5 ms 9684 KB Output is correct
30 Correct 5 ms 9684 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9664 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9664 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 8 ms 9684 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9648 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 5 ms 9684 KB Output is correct
30 Correct 5 ms 9684 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 6 ms 9684 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
38 Correct 6 ms 9704 KB Output is correct
39 Correct 5 ms 9664 KB Output is correct
40 Correct 5 ms 9684 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 5 ms 9768 KB Output is correct
43 Correct 5 ms 9684 KB Output is correct
44 Correct 5 ms 9684 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 5 ms 9684 KB Output is correct
48 Correct 5 ms 9684 KB Output is correct
49 Correct 6 ms 9684 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 6 ms 9684 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9768 KB Output is correct
55 Correct 6 ms 9756 KB Output is correct
56 Correct 5 ms 9760 KB Output is correct
57 Correct 5 ms 9684 KB Output is correct
58 Correct 5 ms 9684 KB Output is correct
59 Correct 5 ms 9684 KB Output is correct
60 Correct 5 ms 9684 KB Output is correct
61 Correct 5 ms 9684 KB Output is correct
62 Correct 6 ms 9684 KB Output is correct
63 Correct 5 ms 9684 KB Output is correct
64 Correct 5 ms 9684 KB Output is correct
65 Correct 5 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 20800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9812 KB Output is correct
2 Correct 7 ms 9860 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 7 ms 9984 KB Output is correct
5 Correct 5 ms 9940 KB Output is correct
6 Correct 5 ms 9940 KB Output is correct
7 Correct 6 ms 9976 KB Output is correct
8 Correct 8 ms 9824 KB Output is correct
9 Correct 8 ms 9812 KB Output is correct
10 Correct 7 ms 9812 KB Output is correct
11 Correct 6 ms 9868 KB Output is correct
12 Correct 6 ms 9848 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9812 KB Output is correct
15 Correct 6 ms 9844 KB Output is correct
16 Correct 6 ms 9852 KB Output is correct
17 Correct 6 ms 9812 KB Output is correct
18 Correct 5 ms 9812 KB Output is correct
19 Correct 5 ms 9812 KB Output is correct
20 Correct 6 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 132 ms 22100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 6 ms 9820 KB Output is correct
4 Correct 7 ms 9820 KB Output is correct
5 Correct 8 ms 9800 KB Output is correct
6 Correct 6 ms 9820 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9820 KB Output is correct
9 Correct 7 ms 9820 KB Output is correct
10 Correct 5 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9940 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Correct 6 ms 9812 KB Output is correct
17 Correct 6 ms 9812 KB Output is correct
18 Correct 5 ms 9812 KB Output is correct
19 Correct 8 ms 9824 KB Output is correct
20 Correct 6 ms 9868 KB Output is correct
21 Correct 6 ms 9812 KB Output is correct
22 Correct 6 ms 9784 KB Output is correct
23 Correct 6 ms 9824 KB Output is correct
24 Correct 6 ms 9816 KB Output is correct
25 Correct 6 ms 9812 KB Output is correct
26 Correct 5 ms 9812 KB Output is correct
27 Correct 5 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 22268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9664 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9664 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 8 ms 9684 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9648 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 5 ms 9684 KB Output is correct
30 Correct 5 ms 9684 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 6 ms 9684 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
38 Correct 6 ms 9704 KB Output is correct
39 Correct 5 ms 9664 KB Output is correct
40 Correct 5 ms 9684 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 5 ms 9768 KB Output is correct
43 Correct 5 ms 9684 KB Output is correct
44 Correct 5 ms 9684 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 5 ms 9684 KB Output is correct
48 Correct 5 ms 9684 KB Output is correct
49 Correct 6 ms 9684 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 6 ms 9684 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9768 KB Output is correct
55 Correct 6 ms 9756 KB Output is correct
56 Correct 5 ms 9760 KB Output is correct
57 Correct 5 ms 9684 KB Output is correct
58 Correct 5 ms 9684 KB Output is correct
59 Correct 5 ms 9684 KB Output is correct
60 Correct 5 ms 9684 KB Output is correct
61 Correct 5 ms 9684 KB Output is correct
62 Correct 6 ms 9684 KB Output is correct
63 Correct 5 ms 9684 KB Output is correct
64 Correct 5 ms 9684 KB Output is correct
65 Correct 5 ms 9676 KB Output is correct
66 Correct 5 ms 9684 KB Output is correct
67 Correct 6 ms 9812 KB Output is correct
68 Correct 6 ms 9812 KB Output is correct
69 Correct 8 ms 9852 KB Output is correct
70 Correct 6 ms 9812 KB Output is correct
71 Correct 5 ms 9812 KB Output is correct
72 Correct 7 ms 9832 KB Output is correct
73 Correct 6 ms 9812 KB Output is correct
74 Correct 6 ms 9812 KB Output is correct
75 Correct 6 ms 9812 KB Output is correct
76 Correct 5 ms 9684 KB Output is correct
77 Correct 5 ms 9812 KB Output is correct
78 Correct 6 ms 9812 KB Output is correct
79 Correct 5 ms 9756 KB Output is correct
80 Correct 5 ms 9812 KB Output is correct
81 Correct 5 ms 9812 KB Output is correct
82 Correct 6 ms 9812 KB Output is correct
83 Correct 6 ms 9812 KB Output is correct
84 Correct 6 ms 9812 KB Output is correct
85 Correct 6 ms 9816 KB Output is correct
86 Correct 8 ms 9812 KB Output is correct
87 Correct 8 ms 9820 KB Output is correct
88 Correct 8 ms 9812 KB Output is correct
89 Correct 7 ms 9812 KB Output is correct
90 Correct 7 ms 9816 KB Output is correct
91 Correct 5 ms 9812 KB Output is correct
92 Correct 6 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
9 Correct 6 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9664 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 5 ms 9664 KB Output is correct
16 Correct 5 ms 9684 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 8 ms 9684 KB Output is correct
19 Correct 7 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9648 KB Output is correct
22 Correct 5 ms 9684 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 5 ms 9684 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 5 ms 9684 KB Output is correct
30 Correct 5 ms 9684 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 6 ms 9684 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
38 Correct 6 ms 9704 KB Output is correct
39 Correct 5 ms 9664 KB Output is correct
40 Correct 5 ms 9684 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 5 ms 9768 KB Output is correct
43 Correct 5 ms 9684 KB Output is correct
44 Correct 5 ms 9684 KB Output is correct
45 Correct 6 ms 9684 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 5 ms 9684 KB Output is correct
48 Correct 5 ms 9684 KB Output is correct
49 Correct 6 ms 9684 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 6 ms 9684 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9768 KB Output is correct
55 Correct 6 ms 9756 KB Output is correct
56 Correct 5 ms 9760 KB Output is correct
57 Correct 5 ms 9684 KB Output is correct
58 Correct 5 ms 9684 KB Output is correct
59 Correct 5 ms 9684 KB Output is correct
60 Correct 5 ms 9684 KB Output is correct
61 Correct 5 ms 9684 KB Output is correct
62 Correct 6 ms 9684 KB Output is correct
63 Correct 5 ms 9684 KB Output is correct
64 Correct 5 ms 9684 KB Output is correct
65 Correct 5 ms 9676 KB Output is correct
66 Incorrect 99 ms 20800 KB Output isn't correct
67 Halted 0 ms 0 KB -