Submission #103233

# Submission time Handle Problem Language Result Execution time Memory
103233 2019-03-29T09:23:56 Z E869120 Duathlon (APIO18_duathlon) C++14
24 / 100
138 ms 13688 KB
#include <iostream>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

long long N, M, A[200009], B[200009], col[100009], col2[100009], cnt1, cnt2, cnts, cntv;
vector<int>X[100009], Y[100009];
vector<int>G[59][59];

void dfs(int pos) {
	if (col[pos] >= 1) return;
	col[pos] = cnts; cnt1 += 1; cnt2 += X[pos].size();
	for (int i = 0; i < X[pos].size(); i++) {
		dfs(X[pos][i]);
	}
}

void dfs2(int pos) {
	if (col2[pos] >= 1) return;
	col2[pos] = cntv;
	for (int i = 0; i < Y[pos].size(); i++) {
		dfs2(Y[pos][i]);
	}
}

long long solve_subtask2() {
	for (int i = 1; i <= N; i++) {
		if (col[i] >= 1) continue;
		cnts++; dfs(i);
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) Y[j].clear();
		for (int j = 1; j <= M; j++) {
			if (A[j] == i || B[j] == i) continue;
			Y[A[j]].push_back(B[j]);
			Y[B[j]].push_back(A[j]);
		}

		cntv = 0;
		for (int j = 1; j <= N; j++) col2[j] = 0;
		for (int j = 1; j <= N; j++) {
			if (col2[j] >= 1) continue;
			cntv++; dfs2(j);
		}

		for (int j = 1; j <= N; j++) {
			for (int k = 1; k <= N; k++) {
				if (col[j] != col[k]) continue;
				if (col2[j] != col2[k]) G[j][k].push_back(i);
			}
		}
	}

	int cnt = 0;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k = 1; k <= N; k++) {
				if (i == j || i == k || j == k || col[i] != col[j] || col[j] != col[k]) continue;

				int d[55]; for (int l = 0; l < 55; l++) d[l] = 0;
				for (int l : G[i][j]) d[l]++;
				for (int l : G[j][k]) d[l]++;

				bool flag = false;
				for (int l = 0; l < 55; l++) {
					if (d[l] >= 2 && l != j) flag = true;
				}

				if (flag == false) {
					cnt++;
				}
			}
		}
	}
	return 1LL * cnt;
}

long long solve_subtask3() {
	long long ans = 0; cnts = 1;
	for (int i = 1; i <= N; i++) {
		if (col[i] >= 1) continue;
		cnt1 = 0; cnt2 = 0;
		dfs(i); cnt2 /= 2;

		if (cnt1 == cnt2) ans += 1LL * cnt1 * (cnt1 - 1) * (cnt1 - 2);
		else ans += 1LL * cnt1 * (cnt1 - 1) * (cnt1 - 2) / 3LL;
	}
	return ans;
}

int main() {
	scanf("%lld%lld", &N, &M);
	for (int i = 1; i <= M; i++) {
		scanf("%lld%lld", &A[i], &B[i]);
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	
	if (N <= 50 && M <= 100) {
		cout << solve_subtask2() << endl;
	}
	else {
		cout << solve_subtask3() << endl;
	}
	return 0;
}

Compilation message

count_triplets.cpp:4:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
count_triplets.cpp: In function 'void dfs(int)':
count_triplets.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < X[pos].size(); i++) {
                  ~~^~~~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs2(int)':
count_triplets.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < Y[pos].size(); i++) {
                  ~~^~~~~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:96:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 8 ms 5252 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 8 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 8 ms 5188 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 8 ms 5248 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 8 ms 5252 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 8 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 8 ms 5188 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 8 ms 5248 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 21 ms 5224 KB Output is correct
39 Correct 20 ms 5248 KB Output is correct
40 Correct 18 ms 5248 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 9 ms 5120 KB Output is correct
43 Correct 9 ms 5248 KB Output is correct
44 Correct 7 ms 5120 KB Output is correct
45 Correct 8 ms 5120 KB Output is correct
46 Correct 10 ms 5120 KB Output is correct
47 Correct 9 ms 5120 KB Output is correct
48 Correct 8 ms 5120 KB Output is correct
49 Correct 9 ms 5120 KB Output is correct
50 Correct 8 ms 5120 KB Output is correct
51 Correct 23 ms 5248 KB Output is correct
52 Correct 22 ms 5248 KB Output is correct
53 Correct 25 ms 5248 KB Output is correct
54 Correct 29 ms 5248 KB Output is correct
55 Correct 28 ms 5348 KB Output is correct
56 Correct 25 ms 5248 KB Output is correct
57 Correct 21 ms 5376 KB Output is correct
58 Correct 27 ms 5368 KB Output is correct
59 Correct 16 ms 5296 KB Output is correct
60 Correct 11 ms 5120 KB Output is correct
61 Correct 8 ms 5120 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 23 ms 5220 KB Output is correct
64 Correct 22 ms 5248 KB Output is correct
65 Correct 29 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 13680 KB Output is correct
2 Correct 118 ms 13688 KB Output is correct
3 Correct 99 ms 12280 KB Output is correct
4 Correct 116 ms 12904 KB Output is correct
5 Correct 101 ms 11640 KB Output is correct
6 Correct 115 ms 11692 KB Output is correct
7 Correct 118 ms 11280 KB Output is correct
8 Correct 125 ms 11488 KB Output is correct
9 Correct 87 ms 11000 KB Output is correct
10 Correct 98 ms 11384 KB Output is correct
11 Correct 63 ms 10360 KB Output is correct
12 Correct 69 ms 10232 KB Output is correct
13 Correct 75 ms 10104 KB Output is correct
14 Correct 69 ms 9772 KB Output is correct
15 Correct 48 ms 9336 KB Output is correct
16 Correct 53 ms 9180 KB Output is correct
17 Correct 10 ms 5888 KB Output is correct
18 Correct 10 ms 5888 KB Output is correct
19 Correct 11 ms 5888 KB Output is correct
20 Correct 10 ms 5888 KB Output is correct
21 Correct 10 ms 5888 KB Output is correct
22 Correct 9 ms 5888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 10744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 10744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 8 ms 5252 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 8 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 8 ms 5188 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 8 ms 5248 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 21 ms 5224 KB Output is correct
39 Correct 20 ms 5248 KB Output is correct
40 Correct 18 ms 5248 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 9 ms 5120 KB Output is correct
43 Correct 9 ms 5248 KB Output is correct
44 Correct 7 ms 5120 KB Output is correct
45 Correct 8 ms 5120 KB Output is correct
46 Correct 10 ms 5120 KB Output is correct
47 Correct 9 ms 5120 KB Output is correct
48 Correct 8 ms 5120 KB Output is correct
49 Correct 9 ms 5120 KB Output is correct
50 Correct 8 ms 5120 KB Output is correct
51 Correct 23 ms 5248 KB Output is correct
52 Correct 22 ms 5248 KB Output is correct
53 Correct 25 ms 5248 KB Output is correct
54 Correct 29 ms 5248 KB Output is correct
55 Correct 28 ms 5348 KB Output is correct
56 Correct 25 ms 5248 KB Output is correct
57 Correct 21 ms 5376 KB Output is correct
58 Correct 27 ms 5368 KB Output is correct
59 Correct 16 ms 5296 KB Output is correct
60 Correct 11 ms 5120 KB Output is correct
61 Correct 8 ms 5120 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 23 ms 5220 KB Output is correct
64 Correct 22 ms 5248 KB Output is correct
65 Correct 29 ms 5248 KB Output is correct
66 Correct 7 ms 5152 KB Output is correct
67 Incorrect 7 ms 5120 KB Output isn't correct
68 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 8 ms 5252 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 8 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 8 ms 5188 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 11 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 8 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 8 ms 5120 KB Output is correct
33 Correct 8 ms 5248 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 6 ms 5120 KB Output is correct
37 Correct 9 ms 5120 KB Output is correct
38 Correct 21 ms 5224 KB Output is correct
39 Correct 20 ms 5248 KB Output is correct
40 Correct 18 ms 5248 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 9 ms 5120 KB Output is correct
43 Correct 9 ms 5248 KB Output is correct
44 Correct 7 ms 5120 KB Output is correct
45 Correct 8 ms 5120 KB Output is correct
46 Correct 10 ms 5120 KB Output is correct
47 Correct 9 ms 5120 KB Output is correct
48 Correct 8 ms 5120 KB Output is correct
49 Correct 9 ms 5120 KB Output is correct
50 Correct 8 ms 5120 KB Output is correct
51 Correct 23 ms 5248 KB Output is correct
52 Correct 22 ms 5248 KB Output is correct
53 Correct 25 ms 5248 KB Output is correct
54 Correct 29 ms 5248 KB Output is correct
55 Correct 28 ms 5348 KB Output is correct
56 Correct 25 ms 5248 KB Output is correct
57 Correct 21 ms 5376 KB Output is correct
58 Correct 27 ms 5368 KB Output is correct
59 Correct 16 ms 5296 KB Output is correct
60 Correct 11 ms 5120 KB Output is correct
61 Correct 8 ms 5120 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 23 ms 5220 KB Output is correct
64 Correct 22 ms 5248 KB Output is correct
65 Correct 29 ms 5248 KB Output is correct
66 Correct 138 ms 13680 KB Output is correct
67 Correct 118 ms 13688 KB Output is correct
68 Correct 99 ms 12280 KB Output is correct
69 Correct 116 ms 12904 KB Output is correct
70 Correct 101 ms 11640 KB Output is correct
71 Correct 115 ms 11692 KB Output is correct
72 Correct 118 ms 11280 KB Output is correct
73 Correct 125 ms 11488 KB Output is correct
74 Correct 87 ms 11000 KB Output is correct
75 Correct 98 ms 11384 KB Output is correct
76 Correct 63 ms 10360 KB Output is correct
77 Correct 69 ms 10232 KB Output is correct
78 Correct 75 ms 10104 KB Output is correct
79 Correct 69 ms 9772 KB Output is correct
80 Correct 48 ms 9336 KB Output is correct
81 Correct 53 ms 9180 KB Output is correct
82 Correct 10 ms 5888 KB Output is correct
83 Correct 10 ms 5888 KB Output is correct
84 Correct 11 ms 5888 KB Output is correct
85 Correct 10 ms 5888 KB Output is correct
86 Correct 10 ms 5888 KB Output is correct
87 Correct 9 ms 5888 KB Output is correct
88 Incorrect 7 ms 5120 KB Output isn't correct
89 Halted 0 ms 0 KB -