Submission #297474

# Submission time Handle Problem Language Result Execution time Memory
297474 2020-09-11T15:14:08 Z srvlt Duathlon (APIO18_duathlon) C++14
30 / 100
76 ms 11788 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x))
#define mem(x, y) memset(& x, y, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int n0 = 1003;
int n, m, root, used[n0], sz[n0];
int up[n0], up2[n0], in[n0], T, last[n0], up3[n0][n0];
vector <int> g[n0];
ll cur;

void dfs(int v, int p) {
	used[v] = 1, sz[v] = 1, in[v] = ++T;
	up[v] = up2[v] = in[v];
	for (int to : g[v]) {
		if (to == p) continue;
		if (used[to] == 1 && in[to] < in[v])
			up[v] = min(up[v], in[to]), up2[v] = min(up2[v], in[to]);
		if (!used[to]) {
			dfs(to, v);
			sz[v] += sz[to];
			up[v] = min(up[v], up[to]);
		}
	}
	used[v] = 2;
}

void dfs2(int v, int p) {
	used[v] = 1;
	if (v == root) last[v] = 1;
	else {
		last[v] = last[p];
		if (up3[p][v] == 1) last[v] = in[p];
		if (up2[v] == 1) last[v] = in[v];
	}
	int mn = -1, mn2 = -1;
	for (int to : g[v]) {
		if (!used[to]) {
			if (mn == -1 || up[mn] > up[to]) {
				mn2 = mn;
				mn = to;
			}	else if (mn2 == -1 || up[mn2] > up[to]) {
				mn2 = to;
			}
		}
	}
	for (int to : g[v]) {
		if (!used[to]) {
			if (mn == to) {
				int x = up2[v];
				if (mn2 != -1) x = min(x, up[mn2]);
				up3[v][to] = x;
			}	else up3[v][to] = min(up2[v], up[mn]);
		}
	}
	bool ok = 0;
	for (int to : g[v])
		if (!used[to])
			if (up[to] == 1) ok = 1;
	if (ok) {
		ll bad = 1;
		for (int to : g[v]) {
			if (used[to]) continue;
			dfs2(to, v);
			if (v != root && up[to] >= in[v]) {
				cur += bad * sz[to];
				bad += sz[to];
			}
		}
	}	else {
		ll bad = 1;
		for (int to : g[v]) {
			if (used[to]) continue;
			dfs2(to, v);
			if (v != root && up[to] >= last[v]) {
				cur += bad * sz[to];
				bad += sz[to];
			}
		}
	}
}

ll comp;
void go(int v) {
	used[v] = 1, comp++;
	for (int to : g[v])
		if (!used[to]) go(to);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y), g[y].pb(x);
	}
	ll res = 0;
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			comp = 0;
			go(i);
			res += comp * (comp - 1) * (comp - 2);
		}
	}
	for (int i = 1; i <= n; i++) {
		root = i, cur = T = 0;
		mem(used, 0);
		dfs(i, i);
		mem(used, 0), mem(last, 0);
		dfs2(i, i);
		cur *= 2;
		res -= cur;
	}
	cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 416 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 416 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Incorrect 1 ms 640 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 11640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 4012 KB Output is correct
2 Correct 61 ms 4088 KB Output is correct
3 Correct 57 ms 4120 KB Output is correct
4 Correct 57 ms 4224 KB Output is correct
5 Correct 60 ms 4216 KB Output is correct
6 Correct 60 ms 4088 KB Output is correct
7 Correct 66 ms 4344 KB Output is correct
8 Correct 61 ms 4216 KB Output is correct
9 Correct 63 ms 4284 KB Output is correct
10 Correct 47 ms 4088 KB Output is correct
11 Correct 50 ms 4088 KB Output is correct
12 Correct 26 ms 4088 KB Output is correct
13 Correct 14 ms 4096 KB Output is correct
14 Correct 4 ms 3968 KB Output is correct
15 Correct 4 ms 3968 KB Output is correct
16 Correct 4 ms 3200 KB Output is correct
17 Correct 36 ms 4344 KB Output is correct
18 Correct 37 ms 4088 KB Output is correct
19 Correct 38 ms 4096 KB Output is correct
20 Correct 39 ms 3808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 53 ms 11768 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 4092 KB Output is correct
2 Correct 61 ms 4064 KB Output is correct
3 Correct 76 ms 4156 KB Output is correct
4 Correct 74 ms 4216 KB Output is correct
5 Correct 70 ms 4216 KB Output is correct
6 Correct 62 ms 4224 KB Output is correct
7 Correct 63 ms 4224 KB Output is correct
8 Correct 60 ms 4224 KB Output is correct
9 Correct 71 ms 4448 KB Output is correct
10 Correct 59 ms 4344 KB Output is correct
11 Correct 61 ms 4224 KB Output is correct
12 Correct 71 ms 4344 KB Output is correct
13 Correct 76 ms 4216 KB Output is correct
14 Correct 74 ms 4344 KB Output is correct
15 Correct 76 ms 4344 KB Output is correct
16 Correct 59 ms 4288 KB Output is correct
17 Correct 47 ms 4216 KB Output is correct
18 Correct 20 ms 4224 KB Output is correct
19 Correct 5 ms 4224 KB Output is correct
20 Correct 4 ms 4096 KB Output is correct
21 Correct 58 ms 4088 KB Output is correct
22 Correct 57 ms 4088 KB Output is correct
23 Correct 63 ms 4216 KB Output is correct
24 Correct 61 ms 4216 KB Output is correct
25 Correct 2 ms 1920 KB Output is correct
26 Correct 2 ms 1184 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 11788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 416 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Incorrect 1 ms 640 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 416 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Incorrect 1 ms 640 KB Output isn't correct
39 Halted 0 ms 0 KB -