Submission #297040

# Submission time Handle Problem Language Result Execution time Memory
297040 2020-09-11T08:16:18 Z srvlt Duathlon (APIO18_duathlon) C++14
25 / 100
28 ms 640 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], good[n0], sz[n0];
vector <int> g[n0];

ll cur;

void dfs(int v, int p) {
	used[v] = 1, sz[v] = 1;
	ll bad = 1;
	for (int to : g[v]) {
		if (to == p) continue;
		if (used[to] == 1 && root == to) {
			good[v] = 1;
		}
		if (!used[to]) {
			dfs(to, v);
			good[v] |= good[to];
			if (v != root && !good[to]) {
				cur += bad * sz[to];
				bad += sz[to];
			}
			sz[v] += sz[to];
		}
	}
	used[v] = 2;
}

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 ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			comp = 0;
			go(i);
			ans += comp * (comp - 1) * (comp - 2);
		}
	}
	for (int i = 1; i <= n; i++) {
		root = i;
		mem(used, 0), mem(good, 0), mem(sz, 0);
		cur = 0;
		dfs(i, i);
		cur *= 2;
		ans -= cur;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Correct 18 ms 472 KB Output is correct
3 Correct 19 ms 512 KB Output is correct
4 Correct 23 ms 512 KB Output is correct
5 Correct 21 ms 632 KB Output is correct
6 Correct 21 ms 512 KB Output is correct
7 Correct 23 ms 512 KB Output is correct
8 Correct 21 ms 512 KB Output is correct
9 Correct 21 ms 512 KB Output is correct
10 Correct 18 ms 384 KB Output is correct
11 Correct 13 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 2 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 12 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 12 ms 384 KB Output is correct
20 Correct 12 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 480 KB Output is correct
2 Correct 19 ms 384 KB Output is correct
3 Correct 21 ms 512 KB Output is correct
4 Correct 21 ms 504 KB Output is correct
5 Correct 25 ms 384 KB Output is correct
6 Correct 23 ms 384 KB Output is correct
7 Correct 23 ms 384 KB Output is correct
8 Correct 23 ms 484 KB Output is correct
9 Correct 22 ms 384 KB Output is correct
10 Correct 28 ms 384 KB Output is correct
11 Correct 23 ms 384 KB Output is correct
12 Correct 26 ms 512 KB Output is correct
13 Correct 25 ms 384 KB Output is correct
14 Correct 26 ms 512 KB Output is correct
15 Correct 24 ms 384 KB Output is correct
16 Correct 19 ms 384 KB Output is correct
17 Correct 15 ms 384 KB Output is correct
18 Correct 7 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 21 ms 384 KB Output is correct
22 Correct 20 ms 384 KB Output is correct
23 Correct 22 ms 384 KB Output is correct
24 Correct 21 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -