/*input
4 4
1 2
2 3
3 4
4 2
4 3
1 2
3 4
4 1
5 4
1 2
2 3
3 4
4 5
4 3
1 2
2 3
3 4
*/
#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 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, w, c = 0;
for (i = st[u]; i; i = nx[i]) if (to[i] != p) {
v = to[i];
// printf("%d - %d\n", u, v); fflush(stdout);
if (!vis[v]) {
++c;
build(v, u);
if (low[v] >= vis[u]) {
++b;
bool cont = true;
while (cont) {
instack[w = (*top--)] = 0;
cont = (w != v);
++bm, bnx[bm] = bst[w], bto[bst[w] = bm] = b;
++bm, bnx[bm] = bst[b], bto[bst[b] = bm] = w;
// printf("%d: %d\n", b, v); fflush(stdout);
}
++bm, bnx[bm] = bst[b], bto[bst[b] = bm] = u;
++bm, bnx[bm] = bst[u], bto[bst[u] = bm] = b;
}
minimize(low[u], low[v]);
} else if (instack[v]) {
minimize(low[u], vis[v]);
}
}
// printf("low[%d] = %d, vis[%d] = %d\n", u, low[u], u, vis[u]); fflush(stdout);
}
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) {
// printf("%d - %d\n", u, bto[i]); fflush(stdout);
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;
// printf("ans %d = %lld\n", u, x * d); fflush(stdout);
}
}
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);
for (i = 1; i <= n; ++i) if (!vis[i]) while (true);
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:92: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:94: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 |
Execution timed out |
1077 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
15608 KB |
Output is correct |
2 |
Correct |
51 ms |
15608 KB |
Output is correct |
3 |
Execution timed out |
1082 ms |
9472 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Execution timed out |
1086 ms |
384 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
8184 KB |
Output is correct |
2 |
Correct |
48 ms |
8184 KB |
Output is correct |
3 |
Correct |
50 ms |
8184 KB |
Output is correct |
4 |
Correct |
48 ms |
8188 KB |
Output is correct |
5 |
Correct |
49 ms |
8184 KB |
Output is correct |
6 |
Correct |
65 ms |
16888 KB |
Output is correct |
7 |
Correct |
57 ms |
13944 KB |
Output is correct |
8 |
Correct |
63 ms |
12528 KB |
Output is correct |
9 |
Correct |
52 ms |
11000 KB |
Output is correct |
10 |
Execution timed out |
1093 ms |
5880 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
532 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Execution timed out |
1099 ms |
384 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
8184 KB |
Output is correct |
2 |
Correct |
51 ms |
8096 KB |
Output is correct |
3 |
Correct |
58 ms |
8056 KB |
Output is correct |
4 |
Correct |
55 ms |
7520 KB |
Output is correct |
5 |
Correct |
54 ms |
6904 KB |
Output is correct |
6 |
Correct |
49 ms |
6520 KB |
Output is correct |
7 |
Correct |
49 ms |
6392 KB |
Output is correct |
8 |
Correct |
48 ms |
6136 KB |
Output is correct |
9 |
Correct |
48 ms |
6136 KB |
Output is correct |
10 |
Correct |
47 ms |
6136 KB |
Output is correct |
11 |
Correct |
46 ms |
6008 KB |
Output is correct |
12 |
Correct |
45 ms |
6136 KB |
Output is correct |
13 |
Correct |
51 ms |
6140 KB |
Output is correct |
14 |
Correct |
46 ms |
7800 KB |
Output is correct |
15 |
Correct |
73 ms |
14072 KB |
Output is correct |
16 |
Correct |
67 ms |
12128 KB |
Output is correct |
17 |
Correct |
63 ms |
13048 KB |
Output is correct |
18 |
Correct |
58 ms |
11256 KB |
Output is correct |
19 |
Execution timed out |
1090 ms |
6648 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |