Submission #241689

# Submission time Handle Problem Language Result Execution time Memory
241689 2020-06-25T09:14:43 Z atoiz Duathlon (APIO18_duathlon) C++14
0 / 100
56 ms 15236 KB
#include <stdio.h>

#define N 100007
#define M 400007
int n, m, to[M], nx[M], st[N], low[N], vis[N], ts, stk[N], instack[N], *top = &stk[0];
int bto[N * 4], bnx[N * 4], bst[N * 2], b, bm, bsz[N * 2];
long long ans = 0;

inline int min(int i, int j) { return i < j ? i : j; }
inline void minimize(int &i, int j) { (i < j ? i = j : 0); }

void build(int u, int p)
{
	low[u] = vis[u] = ++ts;
	instack[*(++top) = u] = 1;

	int i, v, a = 0, c = 0;
	for (i = st[u]; i; i = nx[i]) if (to[i] != p) {
		v = to[i];
		if (!vis[v]) {
			++c;
			build(v, u);
			if (low[v] >= vis[u]) a = 1;
			low[u] = min(low[u], low[v]);
		} else if (instack[v]) {
			low[u] = min(low[u], vis[v]);
		}
	}

	if (a) {
		++b;
		bool cont = true;
		while (cont) {
			instack[v = (*top--)] = 0;
			cont = (v != u);
			++bm, bnx[bm] = bst[v], bto[bst[v] = bm] = b;
			++bm, bnx[bm] = bst[b], bto[bst[b] = bm] = v;
		}
		instack[(*++top) = u] = 1;
	}
}

void solve(int u, int p)
{
	int i, v, d = 0;
	long long x = 0;

	bsz[u] = (u <= n);
	for (i = bst[u]; i; i = bnx[i]) if (bto[i] != p) {
		solve(v = bto[i], u), bsz[u] += bsz[v], ++d;
		x += (long long) bsz[v] * (bsz[v] - 1);
	}

	if (u > n) {
		x += (long long) (n - bsz[u]) * (n - bsz[u] - 1);
		ans -= x * d;
	}
}

int main()
{
	int i, u, v;
	scanf("%d %d", &n, &m);
	for (i = 1; i <= m; ++i) {
		scanf("%d %d", &u, &v);
		nx[i * 2] = st[u], to[st[u] = i * 2] = v;
		nx[i * 2 - 1] = st[v], to[st[v] = i * 2 - 1] = u;
	}

	b = n, build(1, 0);
	ans = (long long) n * (n - 1) * (n - 2), solve(1, 0);
	printf("%lld", ans);
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15236 KB Output is correct
2 Correct 51 ms 15224 KB Output is correct
3 Incorrect 49 ms 10364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -