Submission #49262

# Submission time Handle Problem Language Result Execution time Memory
49262 2018-05-24T15:11:46 Z zadrga Duathlon (APIO18_duathlon) C++14
49 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 100111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;


vector<int> adj[maxn], edge[maxn], tree[maxn];
int num[maxn], low[maxn];
ll c[maxn], two_path[maxn];
bool new_component[maxn];

int n, nn, cnt, BCC;
ll ans;

void DFS(int x){
	nn++;
	num[x] = low[x] = ++cnt;
	for(int v : adj[x]){
		if(!num[v]){
			DFS(v);
			if(low[v] >= num[x])
				new_component[v] = 1;

			tree[x].pb(v);
			low[x] = min(low[x], low[v]);
		}
		else
			low[x] = min(low[x], num[v]);
	}
}

void Add_Edge(int x, int y){
	edge[x].pb(y);
	edge[y].pb(x);
}

void Make_BBC(int x, int component){
	if(component != 0)
		Add_Edge(x, component);

	for(int v : tree[x]){
		if(new_component[v]){
			BCC++;
			Add_Edge(x, BCC);
			Make_BBC(v, BCC);
		}
		else
			Make_BBC(v, component);
	}
}

void Calc(int x, int par){
	if(x <= n)
		c[x] = 1;

	for(int v : edge[x]){
		if(v == par)
			continue;

		Calc(v, x);
		c[x] += c[v];
	}

	for(int v : edge[x]){
		if(v == par)
			two_path[x] += (nn - c[x]) * (nn - c[x] - 1);
		else
			two_path[x] += c[v] * (c[v] - 1);
	}
}

void Go(int x, int par){
	for(int v : edge[x]){
		if(v == par)
			continue;

		Go(v, x);
	}

	if(x > n)
		return;

	ll all_paths = 1LL * (nn - 1) * (nn - 2);
	ll not_valid = 0;
	for(int v : edge[x]){
		if(v == par)
			not_valid += two_path[v] - c[x] * (c[x] - 1);
		else
			not_valid += two_path[v] - (nn - c[v]) * (nn - c[v] - 1);
	}
	ans += all_paths - not_valid;
}

int main(){
	int m;
	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		adj[a].pb(b);
		adj[b].pb(a);
	}

	BCC = n;
	for(int i = 1; i <= n; i++){
		if(!num[i]){
			nn = 0;
			DFS(i);
			Make_BBC(i, 0);
			Calc(i, 0);
			Go(i, 0);
		}
	}

	printf("%lld\n", ans);
	return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:107: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:110:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7380 KB Output is correct
2 Correct 9 ms 7396 KB Output is correct
3 Correct 8 ms 7752 KB Output is correct
4 Correct 8 ms 7752 KB Output is correct
5 Correct 10 ms 7752 KB Output is correct
6 Correct 10 ms 7752 KB Output is correct
7 Correct 8 ms 7752 KB Output is correct
8 Correct 9 ms 7752 KB Output is correct
9 Correct 8 ms 7752 KB Output is correct
10 Correct 8 ms 7752 KB Output is correct
11 Correct 10 ms 7752 KB Output is correct
12 Correct 10 ms 7752 KB Output is correct
13 Correct 10 ms 7752 KB Output is correct
14 Correct 10 ms 7752 KB Output is correct
15 Correct 9 ms 7752 KB Output is correct
16 Correct 9 ms 7752 KB Output is correct
17 Correct 7 ms 7752 KB Output is correct
18 Correct 9 ms 7752 KB Output is correct
19 Correct 8 ms 7752 KB Output is correct
20 Correct 10 ms 7752 KB Output is correct
21 Correct 9 ms 7752 KB Output is correct
22 Correct 8 ms 7752 KB Output is correct
23 Correct 7 ms 7752 KB Output is correct
24 Correct 7 ms 7752 KB Output is correct
25 Correct 8 ms 7752 KB Output is correct
26 Correct 8 ms 7752 KB Output is correct
27 Correct 8 ms 7752 KB Output is correct
28 Correct 9 ms 7752 KB Output is correct
29 Correct 8 ms 7752 KB Output is correct
30 Correct 8 ms 7752 KB Output is correct
31 Correct 8 ms 7752 KB Output is correct
32 Correct 9 ms 7752 KB Output is correct
33 Correct 8 ms 7752 KB Output is correct
34 Correct 8 ms 7752 KB Output is correct
35 Correct 8 ms 7752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7380 KB Output is correct
2 Correct 9 ms 7396 KB Output is correct
3 Correct 8 ms 7752 KB Output is correct
4 Correct 8 ms 7752 KB Output is correct
5 Correct 10 ms 7752 KB Output is correct
6 Correct 10 ms 7752 KB Output is correct
7 Correct 8 ms 7752 KB Output is correct
8 Correct 9 ms 7752 KB Output is correct
9 Correct 8 ms 7752 KB Output is correct
10 Correct 8 ms 7752 KB Output is correct
11 Correct 10 ms 7752 KB Output is correct
12 Correct 10 ms 7752 KB Output is correct
13 Correct 10 ms 7752 KB Output is correct
14 Correct 10 ms 7752 KB Output is correct
15 Correct 9 ms 7752 KB Output is correct
16 Correct 9 ms 7752 KB Output is correct
17 Correct 7 ms 7752 KB Output is correct
18 Correct 9 ms 7752 KB Output is correct
19 Correct 8 ms 7752 KB Output is correct
20 Correct 10 ms 7752 KB Output is correct
21 Correct 9 ms 7752 KB Output is correct
22 Correct 8 ms 7752 KB Output is correct
23 Correct 7 ms 7752 KB Output is correct
24 Correct 7 ms 7752 KB Output is correct
25 Correct 8 ms 7752 KB Output is correct
26 Correct 8 ms 7752 KB Output is correct
27 Correct 8 ms 7752 KB Output is correct
28 Correct 9 ms 7752 KB Output is correct
29 Correct 8 ms 7752 KB Output is correct
30 Correct 8 ms 7752 KB Output is correct
31 Correct 8 ms 7752 KB Output is correct
32 Correct 9 ms 7752 KB Output is correct
33 Correct 8 ms 7752 KB Output is correct
34 Correct 8 ms 7752 KB Output is correct
35 Correct 8 ms 7752 KB Output is correct
36 Correct 9 ms 7752 KB Output is correct
37 Correct 8 ms 7752 KB Output is correct
38 Correct 9 ms 7752 KB Output is correct
39 Correct 8 ms 7752 KB Output is correct
40 Correct 9 ms 7752 KB Output is correct
41 Correct 8 ms 7752 KB Output is correct
42 Correct 10 ms 7752 KB Output is correct
43 Correct 8 ms 7752 KB Output is correct
44 Correct 9 ms 7752 KB Output is correct
45 Correct 9 ms 7752 KB Output is correct
46 Correct 9 ms 7752 KB Output is correct
47 Correct 8 ms 7752 KB Output is correct
48 Correct 9 ms 7752 KB Output is correct
49 Correct 8 ms 7752 KB Output is correct
50 Correct 30 ms 7752 KB Output is correct
51 Correct 8 ms 7752 KB Output is correct
52 Correct 8 ms 7752 KB Output is correct
53 Correct 9 ms 7752 KB Output is correct
54 Correct 8 ms 7776 KB Output is correct
55 Correct 8 ms 7776 KB Output is correct
56 Correct 9 ms 7776 KB Output is correct
57 Correct 8 ms 7776 KB Output is correct
58 Correct 8 ms 7776 KB Output is correct
59 Correct 8 ms 7776 KB Output is correct
60 Correct 8 ms 7776 KB Output is correct
61 Correct 7 ms 7776 KB Output is correct
62 Correct 7 ms 7776 KB Output is correct
63 Correct 8 ms 7776 KB Output is correct
64 Correct 7 ms 7776 KB Output is correct
65 Correct 7 ms 7776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 30676 KB Output is correct
2 Correct 146 ms 30756 KB Output is correct
3 Execution timed out 1077 ms 30756 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 30756 KB Output is correct
2 Correct 9 ms 30756 KB Output is correct
3 Correct 9 ms 30756 KB Output is correct
4 Correct 8 ms 30756 KB Output is correct
5 Correct 9 ms 30756 KB Output is correct
6 Correct 8 ms 30756 KB Output is correct
7 Correct 9 ms 30756 KB Output is correct
8 Correct 8 ms 30756 KB Output is correct
9 Correct 9 ms 30756 KB Output is correct
10 Correct 8 ms 30756 KB Output is correct
11 Correct 9 ms 30756 KB Output is correct
12 Correct 9 ms 30756 KB Output is correct
13 Correct 10 ms 30756 KB Output is correct
14 Correct 8 ms 30756 KB Output is correct
15 Correct 8 ms 30756 KB Output is correct
16 Correct 9 ms 30756 KB Output is correct
17 Correct 8 ms 30756 KB Output is correct
18 Correct 8 ms 30756 KB Output is correct
19 Correct 10 ms 30756 KB Output is correct
20 Correct 9 ms 30756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 1048576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1048576 KB Output is correct
2 Correct 8 ms 1048576 KB Output is correct
3 Correct 11 ms 1048576 KB Output is correct
4 Correct 10 ms 1048576 KB Output is correct
5 Correct 11 ms 1048576 KB Output is correct
6 Correct 10 ms 1048576 KB Output is correct
7 Correct 9 ms 1048576 KB Output is correct
8 Correct 8 ms 1048576 KB Output is correct
9 Correct 11 ms 1048576 KB Output is correct
10 Correct 10 ms 1048576 KB Output is correct
11 Correct 10 ms 1048576 KB Output is correct
12 Correct 9 ms 1048576 KB Output is correct
13 Correct 9 ms 1048576 KB Output is correct
14 Correct 10 ms 1048576 KB Output is correct
15 Correct 9 ms 1048576 KB Output is correct
16 Correct 11 ms 1048576 KB Output is correct
17 Correct 11 ms 1048576 KB Output is correct
18 Correct 11 ms 1048576 KB Output is correct
19 Correct 10 ms 1048576 KB Output is correct
20 Correct 9 ms 1048576 KB Output is correct
21 Correct 13 ms 1048576 KB Output is correct
22 Correct 8 ms 1048576 KB Output is correct
23 Correct 11 ms 1048576 KB Output is correct
24 Correct 10 ms 1048576 KB Output is correct
25 Correct 10 ms 1048576 KB Output is correct
26 Correct 9 ms 1048576 KB Output is correct
27 Correct 8 ms 1048576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 1048576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7380 KB Output is correct
2 Correct 9 ms 7396 KB Output is correct
3 Correct 8 ms 7752 KB Output is correct
4 Correct 8 ms 7752 KB Output is correct
5 Correct 10 ms 7752 KB Output is correct
6 Correct 10 ms 7752 KB Output is correct
7 Correct 8 ms 7752 KB Output is correct
8 Correct 9 ms 7752 KB Output is correct
9 Correct 8 ms 7752 KB Output is correct
10 Correct 8 ms 7752 KB Output is correct
11 Correct 10 ms 7752 KB Output is correct
12 Correct 10 ms 7752 KB Output is correct
13 Correct 10 ms 7752 KB Output is correct
14 Correct 10 ms 7752 KB Output is correct
15 Correct 9 ms 7752 KB Output is correct
16 Correct 9 ms 7752 KB Output is correct
17 Correct 7 ms 7752 KB Output is correct
18 Correct 9 ms 7752 KB Output is correct
19 Correct 8 ms 7752 KB Output is correct
20 Correct 10 ms 7752 KB Output is correct
21 Correct 9 ms 7752 KB Output is correct
22 Correct 8 ms 7752 KB Output is correct
23 Correct 7 ms 7752 KB Output is correct
24 Correct 7 ms 7752 KB Output is correct
25 Correct 8 ms 7752 KB Output is correct
26 Correct 8 ms 7752 KB Output is correct
27 Correct 8 ms 7752 KB Output is correct
28 Correct 9 ms 7752 KB Output is correct
29 Correct 8 ms 7752 KB Output is correct
30 Correct 8 ms 7752 KB Output is correct
31 Correct 8 ms 7752 KB Output is correct
32 Correct 9 ms 7752 KB Output is correct
33 Correct 8 ms 7752 KB Output is correct
34 Correct 8 ms 7752 KB Output is correct
35 Correct 8 ms 7752 KB Output is correct
36 Correct 9 ms 7752 KB Output is correct
37 Correct 8 ms 7752 KB Output is correct
38 Correct 9 ms 7752 KB Output is correct
39 Correct 8 ms 7752 KB Output is correct
40 Correct 9 ms 7752 KB Output is correct
41 Correct 8 ms 7752 KB Output is correct
42 Correct 10 ms 7752 KB Output is correct
43 Correct 8 ms 7752 KB Output is correct
44 Correct 9 ms 7752 KB Output is correct
45 Correct 9 ms 7752 KB Output is correct
46 Correct 9 ms 7752 KB Output is correct
47 Correct 8 ms 7752 KB Output is correct
48 Correct 9 ms 7752 KB Output is correct
49 Correct 8 ms 7752 KB Output is correct
50 Correct 30 ms 7752 KB Output is correct
51 Correct 8 ms 7752 KB Output is correct
52 Correct 8 ms 7752 KB Output is correct
53 Correct 9 ms 7752 KB Output is correct
54 Correct 8 ms 7776 KB Output is correct
55 Correct 8 ms 7776 KB Output is correct
56 Correct 9 ms 7776 KB Output is correct
57 Correct 8 ms 7776 KB Output is correct
58 Correct 8 ms 7776 KB Output is correct
59 Correct 8 ms 7776 KB Output is correct
60 Correct 8 ms 7776 KB Output is correct
61 Correct 7 ms 7776 KB Output is correct
62 Correct 7 ms 7776 KB Output is correct
63 Correct 8 ms 7776 KB Output is correct
64 Correct 7 ms 7776 KB Output is correct
65 Correct 7 ms 7776 KB Output is correct
66 Correct 8 ms 1048576 KB Output is correct
67 Correct 9 ms 1048576 KB Output is correct
68 Correct 9 ms 1048576 KB Output is correct
69 Correct 10 ms 1048576 KB Output is correct
70 Correct 8 ms 1048576 KB Output is correct
71 Correct 7 ms 1048576 KB Output is correct
72 Correct 8 ms 1048576 KB Output is correct
73 Correct 9 ms 1048576 KB Output is correct
74 Correct 9 ms 1048576 KB Output is correct
75 Correct 10 ms 1048576 KB Output is correct
76 Correct 8 ms 1048576 KB Output is correct
77 Correct 9 ms 1048576 KB Output is correct
78 Correct 8 ms 1048576 KB Output is correct
79 Correct 9 ms 1048576 KB Output is correct
80 Correct 8 ms 1048576 KB Output is correct
81 Correct 9 ms 1048576 KB Output is correct
82 Correct 8 ms 1048576 KB Output is correct
83 Correct 8 ms 1048576 KB Output is correct
84 Correct 8 ms 1048576 KB Output is correct
85 Correct 8 ms 1048576 KB Output is correct
86 Correct 9 ms 1048576 KB Output is correct
87 Correct 10 ms 1048576 KB Output is correct
88 Correct 10 ms 1048576 KB Output is correct
89 Correct 10 ms 1048576 KB Output is correct
90 Correct 9 ms 1048576 KB Output is correct
91 Correct 12 ms 1048576 KB Output is correct
92 Correct 9 ms 1048576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7380 KB Output is correct
2 Correct 9 ms 7396 KB Output is correct
3 Correct 8 ms 7752 KB Output is correct
4 Correct 8 ms 7752 KB Output is correct
5 Correct 10 ms 7752 KB Output is correct
6 Correct 10 ms 7752 KB Output is correct
7 Correct 8 ms 7752 KB Output is correct
8 Correct 9 ms 7752 KB Output is correct
9 Correct 8 ms 7752 KB Output is correct
10 Correct 8 ms 7752 KB Output is correct
11 Correct 10 ms 7752 KB Output is correct
12 Correct 10 ms 7752 KB Output is correct
13 Correct 10 ms 7752 KB Output is correct
14 Correct 10 ms 7752 KB Output is correct
15 Correct 9 ms 7752 KB Output is correct
16 Correct 9 ms 7752 KB Output is correct
17 Correct 7 ms 7752 KB Output is correct
18 Correct 9 ms 7752 KB Output is correct
19 Correct 8 ms 7752 KB Output is correct
20 Correct 10 ms 7752 KB Output is correct
21 Correct 9 ms 7752 KB Output is correct
22 Correct 8 ms 7752 KB Output is correct
23 Correct 7 ms 7752 KB Output is correct
24 Correct 7 ms 7752 KB Output is correct
25 Correct 8 ms 7752 KB Output is correct
26 Correct 8 ms 7752 KB Output is correct
27 Correct 8 ms 7752 KB Output is correct
28 Correct 9 ms 7752 KB Output is correct
29 Correct 8 ms 7752 KB Output is correct
30 Correct 8 ms 7752 KB Output is correct
31 Correct 8 ms 7752 KB Output is correct
32 Correct 9 ms 7752 KB Output is correct
33 Correct 8 ms 7752 KB Output is correct
34 Correct 8 ms 7752 KB Output is correct
35 Correct 8 ms 7752 KB Output is correct
36 Correct 9 ms 7752 KB Output is correct
37 Correct 8 ms 7752 KB Output is correct
38 Correct 9 ms 7752 KB Output is correct
39 Correct 8 ms 7752 KB Output is correct
40 Correct 9 ms 7752 KB Output is correct
41 Correct 8 ms 7752 KB Output is correct
42 Correct 10 ms 7752 KB Output is correct
43 Correct 8 ms 7752 KB Output is correct
44 Correct 9 ms 7752 KB Output is correct
45 Correct 9 ms 7752 KB Output is correct
46 Correct 9 ms 7752 KB Output is correct
47 Correct 8 ms 7752 KB Output is correct
48 Correct 9 ms 7752 KB Output is correct
49 Correct 8 ms 7752 KB Output is correct
50 Correct 30 ms 7752 KB Output is correct
51 Correct 8 ms 7752 KB Output is correct
52 Correct 8 ms 7752 KB Output is correct
53 Correct 9 ms 7752 KB Output is correct
54 Correct 8 ms 7776 KB Output is correct
55 Correct 8 ms 7776 KB Output is correct
56 Correct 9 ms 7776 KB Output is correct
57 Correct 8 ms 7776 KB Output is correct
58 Correct 8 ms 7776 KB Output is correct
59 Correct 8 ms 7776 KB Output is correct
60 Correct 8 ms 7776 KB Output is correct
61 Correct 7 ms 7776 KB Output is correct
62 Correct 7 ms 7776 KB Output is correct
63 Correct 8 ms 7776 KB Output is correct
64 Correct 7 ms 7776 KB Output is correct
65 Correct 7 ms 7776 KB Output is correct
66 Correct 145 ms 30676 KB Output is correct
67 Correct 146 ms 30756 KB Output is correct
68 Execution timed out 1077 ms 30756 KB Time limit exceeded
69 Halted 0 ms 0 KB -