답안 #111239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111239 2019-05-14T12:29:29 Z diamond_duke 철인 이종 경기 (APIO18_duathlon) C++11
49 / 100
66 ms 20288 KB
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using ll = long long;
int lst[100005], to[200005], pre[200005], tot;
int low[100005], dfn[100005], st[100005], clk, tp;
int sz[100005], n, m, t_cnt;
std::vector<int> son[100005];
ll ans;
inline void add_edge(int u, int v)
{
	to[tot] = v;
	pre[tot] = lst[u];
	lst[u] = tot++;
}
void tarjan(int u, int fa = -1)
{
	dfn[u] = low[u] = clk++;
	st[tp++] = u;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		int v = to[i];
		if (-1 == dfn[v])
		{
			tarjan(v, i ^ 1);
			low[u] = std::min(low[u], low[v]);
			if (low[v] >= dfn[u])
			{
				son[u].push_back(t_cnt);
				do
					son[t_cnt].push_back(st[--tp]);
				while (st[tp] != v);
				t_cnt++;
			}
		}
		else if (i != fa)
			low[u] = std::min(low[u], dfn[v]);
	}
}
void dfs(int u)
{
	sz[u] = u < n;
	for (int v : son[u])
	{
		dfs(v);
		sz[u] += sz[v];
	}
}
void work(int u, int rt, int fa = -1)
{
	for (int v : son[u])
	{
		if (u < n)
			ans += (ll)sz[v] * (sz[rt] - sz[v] - 1);
		else
			ans += (ll)sz[v] * (sz[rt] - sz[v]) * (son[u].size() - 1);
		work(v, rt, u);
	}
	if (~fa)
	{
		if (u < n)
			ans += (ll)(sz[rt] - sz[u]) * (sz[u] - 1);
		else
			ans += (ll)(sz[rt] - sz[u]) * sz[u] * (son[u].size() - 1);
	}
}
int main()
{
	// freopen("uoj-416.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	memset(dfn, -1, sizeof(dfn));
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		add_edge(--u, --v);
		add_edge(v, u);
	}
	t_cnt = n;
	for (int i = 0; i < n; i++)
	{
		if (-1 == dfn[i])
		{
			tarjan(i);
			dfs(i);
			work(i, i);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:73: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:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3456 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 8 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 5 ms 3328 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 6 ms 3456 KB Output is correct
8 Correct 5 ms 3456 KB Output is correct
9 Correct 5 ms 3428 KB Output is correct
10 Correct 5 ms 3428 KB Output is correct
11 Correct 5 ms 3456 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 6 ms 3584 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 6 ms 3456 KB Output is correct
23 Correct 4 ms 3456 KB Output is correct
24 Correct 4 ms 3532 KB Output is correct
25 Correct 5 ms 3456 KB Output is correct
26 Correct 5 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 5 ms 3456 KB Output is correct
29 Correct 5 ms 3456 KB Output is correct
30 Correct 5 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 5 ms 3456 KB Output is correct
34 Correct 6 ms 3456 KB Output is correct
35 Correct 20 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3456 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 8 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 5 ms 3328 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 6 ms 3456 KB Output is correct
8 Correct 5 ms 3456 KB Output is correct
9 Correct 5 ms 3428 KB Output is correct
10 Correct 5 ms 3428 KB Output is correct
11 Correct 5 ms 3456 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 6 ms 3584 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 6 ms 3456 KB Output is correct
23 Correct 4 ms 3456 KB Output is correct
24 Correct 4 ms 3532 KB Output is correct
25 Correct 5 ms 3456 KB Output is correct
26 Correct 5 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 5 ms 3456 KB Output is correct
29 Correct 5 ms 3456 KB Output is correct
30 Correct 5 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 5 ms 3456 KB Output is correct
34 Correct 6 ms 3456 KB Output is correct
35 Correct 20 ms 3456 KB Output is correct
36 Correct 6 ms 3456 KB Output is correct
37 Correct 4 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 4 ms 3456 KB Output is correct
41 Correct 5 ms 3456 KB Output is correct
42 Correct 6 ms 3456 KB Output is correct
43 Correct 6 ms 3456 KB Output is correct
44 Correct 6 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 4 ms 3456 KB Output is correct
47 Correct 5 ms 3500 KB Output is correct
48 Correct 5 ms 3584 KB Output is correct
49 Correct 6 ms 3456 KB Output is correct
50 Correct 4 ms 3456 KB Output is correct
51 Correct 6 ms 3456 KB Output is correct
52 Correct 6 ms 3456 KB Output is correct
53 Correct 5 ms 3456 KB Output is correct
54 Correct 4 ms 3456 KB Output is correct
55 Correct 4 ms 3456 KB Output is correct
56 Correct 4 ms 3456 KB Output is correct
57 Correct 4 ms 3456 KB Output is correct
58 Correct 5 ms 3456 KB Output is correct
59 Correct 5 ms 3456 KB Output is correct
60 Correct 5 ms 3456 KB Output is correct
61 Correct 5 ms 3456 KB Output is correct
62 Correct 5 ms 3456 KB Output is correct
63 Correct 5 ms 3456 KB Output is correct
64 Correct 5 ms 3456 KB Output is correct
65 Correct 5 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 14576 KB Output is correct
2 Correct 52 ms 14552 KB Output is correct
3 Runtime error 60 ms 20288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3556 KB Output is correct
2 Correct 4 ms 3456 KB Output is correct
3 Correct 5 ms 3584 KB Output is correct
4 Correct 6 ms 3712 KB Output is correct
5 Correct 4 ms 3584 KB Output is correct
6 Correct 5 ms 3584 KB Output is correct
7 Correct 5 ms 3584 KB Output is correct
8 Correct 5 ms 3584 KB Output is correct
9 Correct 5 ms 3584 KB Output is correct
10 Correct 5 ms 3584 KB Output is correct
11 Correct 4 ms 3584 KB Output is correct
12 Correct 5 ms 3584 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 5 ms 3584 KB Output is correct
16 Correct 4 ms 3456 KB Output is correct
17 Correct 4 ms 3584 KB Output is correct
18 Correct 4 ms 3584 KB Output is correct
19 Correct 4 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 9960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3584 KB Output is correct
2 Correct 4 ms 3584 KB Output is correct
3 Correct 4 ms 3456 KB Output is correct
4 Correct 6 ms 3584 KB Output is correct
5 Correct 6 ms 3584 KB Output is correct
6 Correct 6 ms 3456 KB Output is correct
7 Correct 4 ms 3456 KB Output is correct
8 Correct 4 ms 3456 KB Output is correct
9 Correct 5 ms 3584 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
11 Correct 5 ms 3584 KB Output is correct
12 Correct 6 ms 3584 KB Output is correct
13 Correct 5 ms 3584 KB Output is correct
14 Correct 6 ms 3556 KB Output is correct
15 Correct 5 ms 3584 KB Output is correct
16 Correct 5 ms 3456 KB Output is correct
17 Correct 4 ms 3456 KB Output is correct
18 Correct 8 ms 3584 KB Output is correct
19 Correct 6 ms 3584 KB Output is correct
20 Correct 7 ms 3584 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 5 ms 3564 KB Output is correct
23 Correct 5 ms 3456 KB Output is correct
24 Correct 5 ms 3456 KB Output is correct
25 Correct 5 ms 3456 KB Output is correct
26 Correct 5 ms 3456 KB Output is correct
27 Correct 5 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 38 ms 9876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3456 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 8 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 5 ms 3328 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 6 ms 3456 KB Output is correct
8 Correct 5 ms 3456 KB Output is correct
9 Correct 5 ms 3428 KB Output is correct
10 Correct 5 ms 3428 KB Output is correct
11 Correct 5 ms 3456 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 6 ms 3584 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 6 ms 3456 KB Output is correct
23 Correct 4 ms 3456 KB Output is correct
24 Correct 4 ms 3532 KB Output is correct
25 Correct 5 ms 3456 KB Output is correct
26 Correct 5 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 5 ms 3456 KB Output is correct
29 Correct 5 ms 3456 KB Output is correct
30 Correct 5 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 5 ms 3456 KB Output is correct
34 Correct 6 ms 3456 KB Output is correct
35 Correct 20 ms 3456 KB Output is correct
36 Correct 6 ms 3456 KB Output is correct
37 Correct 4 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 4 ms 3456 KB Output is correct
41 Correct 5 ms 3456 KB Output is correct
42 Correct 6 ms 3456 KB Output is correct
43 Correct 6 ms 3456 KB Output is correct
44 Correct 6 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 4 ms 3456 KB Output is correct
47 Correct 5 ms 3500 KB Output is correct
48 Correct 5 ms 3584 KB Output is correct
49 Correct 6 ms 3456 KB Output is correct
50 Correct 4 ms 3456 KB Output is correct
51 Correct 6 ms 3456 KB Output is correct
52 Correct 6 ms 3456 KB Output is correct
53 Correct 5 ms 3456 KB Output is correct
54 Correct 4 ms 3456 KB Output is correct
55 Correct 4 ms 3456 KB Output is correct
56 Correct 4 ms 3456 KB Output is correct
57 Correct 4 ms 3456 KB Output is correct
58 Correct 5 ms 3456 KB Output is correct
59 Correct 5 ms 3456 KB Output is correct
60 Correct 5 ms 3456 KB Output is correct
61 Correct 5 ms 3456 KB Output is correct
62 Correct 5 ms 3456 KB Output is correct
63 Correct 5 ms 3456 KB Output is correct
64 Correct 5 ms 3456 KB Output is correct
65 Correct 5 ms 3456 KB Output is correct
66 Correct 5 ms 3456 KB Output is correct
67 Correct 6 ms 3556 KB Output is correct
68 Correct 5 ms 3584 KB Output is correct
69 Correct 5 ms 3500 KB Output is correct
70 Correct 7 ms 3584 KB Output is correct
71 Correct 5 ms 3584 KB Output is correct
72 Correct 7 ms 3456 KB Output is correct
73 Correct 5 ms 3584 KB Output is correct
74 Correct 5 ms 3584 KB Output is correct
75 Correct 5 ms 3456 KB Output is correct
76 Correct 5 ms 3456 KB Output is correct
77 Correct 6 ms 3532 KB Output is correct
78 Correct 6 ms 3584 KB Output is correct
79 Correct 7 ms 3456 KB Output is correct
80 Correct 6 ms 3456 KB Output is correct
81 Correct 6 ms 3456 KB Output is correct
82 Correct 4 ms 3456 KB Output is correct
83 Correct 6 ms 3584 KB Output is correct
84 Correct 7 ms 3584 KB Output is correct
85 Correct 7 ms 3580 KB Output is correct
86 Correct 7 ms 3456 KB Output is correct
87 Correct 4 ms 3584 KB Output is correct
88 Correct 5 ms 3584 KB Output is correct
89 Correct 5 ms 3584 KB Output is correct
90 Correct 4 ms 3456 KB Output is correct
91 Correct 6 ms 3456 KB Output is correct
92 Correct 6 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3456 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 8 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 5 ms 3328 KB Output is correct
6 Correct 4 ms 3456 KB Output is correct
7 Correct 6 ms 3456 KB Output is correct
8 Correct 5 ms 3456 KB Output is correct
9 Correct 5 ms 3428 KB Output is correct
10 Correct 5 ms 3428 KB Output is correct
11 Correct 5 ms 3456 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 4 ms 3456 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 6 ms 3584 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 6 ms 3456 KB Output is correct
23 Correct 4 ms 3456 KB Output is correct
24 Correct 4 ms 3532 KB Output is correct
25 Correct 5 ms 3456 KB Output is correct
26 Correct 5 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 5 ms 3456 KB Output is correct
29 Correct 5 ms 3456 KB Output is correct
30 Correct 5 ms 3456 KB Output is correct
31 Correct 4 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 5 ms 3456 KB Output is correct
34 Correct 6 ms 3456 KB Output is correct
35 Correct 20 ms 3456 KB Output is correct
36 Correct 6 ms 3456 KB Output is correct
37 Correct 4 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 4 ms 3456 KB Output is correct
41 Correct 5 ms 3456 KB Output is correct
42 Correct 6 ms 3456 KB Output is correct
43 Correct 6 ms 3456 KB Output is correct
44 Correct 6 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 4 ms 3456 KB Output is correct
47 Correct 5 ms 3500 KB Output is correct
48 Correct 5 ms 3584 KB Output is correct
49 Correct 6 ms 3456 KB Output is correct
50 Correct 4 ms 3456 KB Output is correct
51 Correct 6 ms 3456 KB Output is correct
52 Correct 6 ms 3456 KB Output is correct
53 Correct 5 ms 3456 KB Output is correct
54 Correct 4 ms 3456 KB Output is correct
55 Correct 4 ms 3456 KB Output is correct
56 Correct 4 ms 3456 KB Output is correct
57 Correct 4 ms 3456 KB Output is correct
58 Correct 5 ms 3456 KB Output is correct
59 Correct 5 ms 3456 KB Output is correct
60 Correct 5 ms 3456 KB Output is correct
61 Correct 5 ms 3456 KB Output is correct
62 Correct 5 ms 3456 KB Output is correct
63 Correct 5 ms 3456 KB Output is correct
64 Correct 5 ms 3456 KB Output is correct
65 Correct 5 ms 3456 KB Output is correct
66 Correct 66 ms 14576 KB Output is correct
67 Correct 52 ms 14552 KB Output is correct
68 Runtime error 60 ms 20288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
69 Halted 0 ms 0 KB -